From e9a6abfe4434aeb4d267838d363850f466f56691 Mon Sep 17 00:00:00 2001 From: kolaente Date: Fri, 6 Feb 2026 10:46:37 +0100 Subject: [PATCH] refactor: extract auth route names into shared constant Move the list of authentication route names (login, register, password reset, openid, link-share) into a shared constant in src/constants/authRouteNames.ts. Use it in both App.vue (layout gate) and router/index.ts (auth redirect guard) to keep them in sync. --- frontend/src/App.vue | 8 +------- frontend/src/constants/authRouteNames.ts | 13 +++++++++++++ frontend/src/router/index.ts | 10 ++-------- 3 files changed, 16 insertions(+), 15 deletions(-) create mode 100644 frontend/src/constants/authRouteNames.ts diff --git a/frontend/src/App.vue b/frontend/src/App.vue index 0a34367c7..f9164c699 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -48,6 +48,7 @@ import {useColorScheme} from '@/composables/useColorScheme' import {useBodyClass} from '@/composables/useBodyClass' import AddToHomeScreen from '@/components/home/AddToHomeScreen.vue' import DemoMode from '@/components/home/DemoMode.vue' +import {AUTH_ROUTE_NAMES} from '@/constants/authRouteNames' const importAccountDeleteService = () => import('@/services/accountDelete') import {success} from '@/message' @@ -57,13 +58,6 @@ const baseStore = useBaseStore() const route = useRoute() -const AUTH_ROUTE_NAMES = new Set([ - 'user.login', - 'user.register', - 'user.password-reset.request', - 'user.password-reset.reset', - 'openid.auth', -]) const showAuthLayout = computed(() => authStore.authUser && !AUTH_ROUTE_NAMES.has(route.name as string)) useBodyClass('is-touch', isTouchDevice()) diff --git a/frontend/src/constants/authRouteNames.ts b/frontend/src/constants/authRouteNames.ts new file mode 100644 index 000000000..afc5116da --- /dev/null +++ b/frontend/src/constants/authRouteNames.ts @@ -0,0 +1,13 @@ +/** + * Route names for authentication pages that don't require (and shouldn't show) + * the authenticated app shell. Used by App.vue to gate the layout switch and + * by the router guard to identify routes that don't need authentication. + */ +export const AUTH_ROUTE_NAMES = new Set([ + 'user.login', + 'user.register', + 'user.password-reset.request', + 'user.password-reset.reset', + 'link-share.auth', + 'openid.auth', +]) diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.ts index ecedb5636..3bc9ec7f0 100644 --- a/frontend/src/router/index.ts +++ b/frontend/src/router/index.ts @@ -6,6 +6,7 @@ import {getProjectViewId} from '@/helpers/projectView' import {parseDateOrString} from '@/helpers/time/parseDateOrString' import {getNextWeekDate} from '@/helpers/time/getNextWeekDate' import {LINK_SHARE_HASH_PREFIX} from '@/constants/linkShareHash' +import {AUTH_ROUTE_NAMES} from '@/constants/authRouteNames' import {useAuthStore} from '@/stores/auth' @@ -421,14 +422,7 @@ export async function getAuthForRoute(to: RouteLocation, authStore) { // Check if the route the user wants to go to is a route which needs authentication. We use this to // redirect the user after successful login. - const isValidUserAppRoute = ![ - 'user.login', - 'user.password-reset.request', - 'user.password-reset.reset', - 'user.register', - 'link-share.auth', - 'openid.auth', - ].includes(to.name as string) && + const isValidUserAppRoute = !AUTH_ROUTE_NAMES.has(to.name as string) && localStorage.getItem('emailConfirmToken') === null if (isValidUserAppRoute) {