From d6e56bc16f1abef373f755dd55659ef6d7a21287 Mon Sep 17 00:00:00 2001 From: sadnub Date: Mon, 27 Jan 2025 02:01:57 -0500 Subject: [PATCH] redirect to last url when auth session expires --- src/ee/sso/views/ProviderCallback.vue | 4 ++++ src/router/routes.js | 6 ++++++ src/stores/auth.ts | 1 + src/views/LoginView.vue | 7 ++++++- 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/ee/sso/views/ProviderCallback.vue b/src/ee/sso/views/ProviderCallback.vue index 749353f1..16fceb11 100644 --- a/src/ee/sso/views/ProviderCallback.vue +++ b/src/ee/sso/views/ProviderCallback.vue @@ -24,6 +24,10 @@ const router = useRouter(); const auth = useAuthStore(); if (!error) { if (auth.loggedIn) { + if (auth.next) { + router.push(auth.next); + auth.next = null; + } router.push({ name: "Dashboard" }); } else { router.push({ name: "Login" }); diff --git a/src/router/routes.js b/src/router/routes.js index ae418229..3bbe9190 100644 --- a/src/router/routes.js +++ b/src/router/routes.js @@ -1,3 +1,5 @@ +import { useAuthStore } from "@/stores/auth"; + const routes = [ { path: "/", @@ -74,6 +76,10 @@ const routes = [ path: "/expired", name: "SessionExpired", component: () => import("@/views/SessionExpired.vue"), + beforeEnter: (_, from) => { + const auth = useAuthStore(); + auth.next = from.fullPath; + }, }, { path: "/:catchAll(.*)", component: () => import("@/views/NotFound.vue") }, ]; diff --git a/src/stores/auth.ts b/src/stores/auth.ts index 61ec197c..6e8b8e19 100644 --- a/src/stores/auth.ts +++ b/src/stores/auth.ts @@ -32,6 +32,7 @@ export const useAuthStore = defineStore("auth", { token: useStorage("access_token", null), ssoLoginProvider: useStorage("sso_provider", null), provider_id: useStorage("provider_id", null), + next: useStorage("next", null), }), getters: { loggedIn: (state) => { diff --git a/src/views/LoginView.vue b/src/views/LoginView.vue index 27285b0a..244fde0d 100644 --- a/src/views/LoginView.vue +++ b/src/views/LoginView.vue @@ -159,7 +159,12 @@ async function checkCreds() { async function onSubmit() { try { await auth.login({ ...credentials, twofactor: twofactor.value }); - router.push({ name: "Dashboard" }); + if (auth.next) { + router.push(auth.next); + auth.next = null; + } else { + router.push({ name: "Dashboard" }); + } } catch (err) { console.error(err); } finally {