From 7c548bf1e455b988d2d879e984804d1ef47ffa49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20P=C4=99dzich?= Date: Wed, 7 Jun 2023 10:31:06 +0200 Subject: [PATCH] Remove Apprwite-related code --- .husky/pre-commit | 4 -- src/App.vue | 44 +------------- src/appwrite.ts | 12 ---- src/composables/useAuth.ts | 56 ------------------ src/global.d.ts | 10 ---- src/guards/auth.ts | 19 ------ src/router/index.ts | 3 - src/views/LogIn.vue | 25 -------- src/views/Vote.vue | 117 +------------------------------------ 9 files changed, 3 insertions(+), 287 deletions(-) delete mode 100755 .husky/pre-commit delete mode 100644 src/appwrite.ts delete mode 100644 src/composables/useAuth.ts delete mode 100644 src/global.d.ts delete mode 100644 src/guards/auth.ts delete mode 100644 src/views/LogIn.vue diff --git a/.husky/pre-commit b/.husky/pre-commit deleted file mode 100755 index 9e5a7b4..0000000 --- a/.husky/pre-commit +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env sh -. "$(dirname -- "$0")/_/husky.sh" - -npm run prettier-format && npm run lint diff --git a/src/App.vue b/src/App.vue index be8a0c5..d058949 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,54 +1,14 @@ diff --git a/src/appwrite.ts b/src/appwrite.ts deleted file mode 100644 index e7e16ba..0000000 --- a/src/appwrite.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { Account, Avatars, Client, Databases, Storage } from 'appwrite'; - -const appwriteClient = new Client(); - -appwriteClient - .setEndpoint(import.meta.env.VITE_APPWRITE_ENDPOINT) - .setProject(import.meta.env.VITE_APPWRITE_PROJECT_ID); - -export const account = new Account(appwriteClient); -export const avatars = new Avatars(appwriteClient); -export const databases = new Databases(appwriteClient); -export const storage = new Storage(appwriteClient); diff --git a/src/composables/useAuth.ts b/src/composables/useAuth.ts deleted file mode 100644 index 0e9d2f9..0000000 --- a/src/composables/useAuth.ts +++ /dev/null @@ -1,56 +0,0 @@ -import { ref, computed } from 'vue'; -import { Models } from 'appwrite'; - -import { account } from '@/appwrite'; - -const user = ref | null>(null); -const loadingUserFinished = ref(false); -const isLoggedIn = computed(() => !!user.value); - -export function useAuth() { - const logIn = (provider: 'github' | 'discord') => { - const redirectPath = localStorage.getItem('redirectPath') || '/'; - const permissionScopes = - provider === 'github' - ? ['read:user', 'user:email'] - : ['identify', 'email']; - - account.createOAuth2Session( - provider, - `${location.origin}${redirectPath}#login-success`, - `${location.origin}/log-in#login-error`, - permissionScopes - ); - }; - - const loadUser = async () => { - try { - if (loadingUserFinished.value) return; - - const currentUser = await account.get(); - user.value = currentUser; - } catch (error) { - if (import.meta.env.DEV) { - console.error(error); - } - - user.value = null; - } finally { - loadingUserFinished.value = true; - } - }; - - const logOut = async () => { - await account.deleteSession('current'); - user.value = null; - }; - - return { - user, - loadingUserFinished, - isLoggedIn, - logIn, - loadUser, - logOut - }; -} diff --git a/src/global.d.ts b/src/global.d.ts deleted file mode 100644 index de183f8..0000000 --- a/src/global.d.ts +++ /dev/null @@ -1,10 +0,0 @@ -interface ImportMetaEnv { - BASE_URL: string; - VITE_APPWRITE_ENDPOINT: string; - VITE_APPWRITE_PROJECT_ID: string; - VITE_DATABASE_ID: string; - VITE_PHOTOS_COLLECTION_ID: string; - VITE_VOTES_COLLECTION_ID: string; - VITE_PHOTO_APPEARANCE_COUNT_COLLECTION_ID: string; - VITE_NUMBER_OF_PHOTOS: number; -} diff --git a/src/guards/auth.ts b/src/guards/auth.ts deleted file mode 100644 index 2c5a1e6..0000000 --- a/src/guards/auth.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { RouteLocationNormalized, NavigationGuardNext } from 'vue-router'; -import { useAuth } from '@/composables/useAuth'; - -export async function authGuard( - to: RouteLocationNormalized, - from: RouteLocationNormalized, - next: NavigationGuardNext -) { - const { isLoggedIn, loadUser } = useAuth(); - - await loadUser(); - - if (!to.meta.authRequired || isLoggedIn.value) { - return next(); - } else { - localStorage.setItem('redirectPath', to.fullPath); - return next('/log-in'); - } -} diff --git a/src/router/index.ts b/src/router/index.ts index 2748595..4ea5471 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -1,6 +1,5 @@ import { createRouter, createWebHistory } from 'vue-router'; -import { authGuard } from '@/guards/auth'; import Home from '@/views/Home.vue'; const routes = [ @@ -27,6 +26,4 @@ const router = createRouter({ routes }); -router.beforeEach(authGuard); - export default router; diff --git a/src/views/LogIn.vue b/src/views/LogIn.vue deleted file mode 100644 index 37b37f6..0000000 --- a/src/views/LogIn.vue +++ /dev/null @@ -1,25 +0,0 @@ - - - diff --git a/src/views/Vote.vue b/src/views/Vote.vue index 3bb5d82..1573177 100644 --- a/src/views/Vote.vue +++ b/src/views/Vote.vue @@ -1,9 +1,6 @@