From 643d74e29db0e1f8a5267b0ff47e957a0a3588d6 Mon Sep 17 00:00:00 2001 From: Patrick Toal Date: Fri, 14 Jun 2024 16:23:48 -0400 Subject: [PATCH] feat: (auth) switch to OTP code via e-mail --- src/pages/LoginPage.vue | 88 ++++++++++++++++++++++++++++++++--------- src/router/index.ts | 4 ++ src/stores/auth.ts | 19 +++++++-- 3 files changed, 89 insertions(+), 22 deletions(-) diff --git a/src/pages/LoginPage.vue b/src/pages/LoginPage.vue index 2a35038..a9fa9ca 100644 --- a/src/pages/LoginPage.vue +++ b/src/pages/LoginPage.vue @@ -14,7 +14,7 @@
Log in
- + - - - -
@@ -84,16 +77,75 @@ diff --git a/src/router/index.ts b/src/router/index.ts index b77afbf..6f189a5 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -49,6 +49,10 @@ export default route(function (/* { store, ssrContext } */) { return next('/login'); } + if (to.name === 'login' && currentUser) { + return next('/'); + } + if (requiredRoles) { if (!currentUser) { return next('/login'); diff --git a/src/stores/auth.ts b/src/stores/auth.ts index eb9cfc6..0f39525 100644 --- a/src/stores/auth.ts +++ b/src/stores/auth.ts @@ -45,22 +45,31 @@ export const useAuthStore = defineStore('auth', () => { await init(); } + async function createTokenSession(email: string) { + return await account.createEmailToken(ID.unique(), email); + } + async function googleLogin() { - account.createOAuth2Session( + await account.createOAuth2Session( OAuthProvider.Google, 'https://oys.undock.ca', 'https://oys.undock.ca/login' ); - currentUser.value = await account.get(); + await init(); } async function discordLogin() { - account.createOAuth2Session( + await account.createOAuth2Session( OAuthProvider.Discord, 'https://oys.undock.ca', 'https://oys.undock.ca/login' ); - currentUser.value = await account.get(); + await init(); + } + + async function tokenLogin(userId: string, token: string) { + await account.createSession(userId, token); + await init(); } function getUserNameById(id: string | undefined | null): string { @@ -102,6 +111,8 @@ export const useAuthStore = defineStore('auth', () => { login, googleLogin, discordLogin, + createTokenSession, + tokenLogin, logout, init, };