mirror of
https://github.com/go-vikunja/vikunja.git
synced 2026-03-11 17:48:44 -05:00
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.
This commit is contained in:
@@ -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())
|
||||
|
||||
13
frontend/src/constants/authRouteNames.ts
Normal file
13
frontend/src/constants/authRouteNames.ts
Normal file
@@ -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',
|
||||
])
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user