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, };