refactor: centralize validation, error handling, and formatting logic
Extract shared auth logic and validation rules to shared/auth.ts Introduce utility functions for HTTP errors and user input parsing Standardize error messages and date formatting across the app
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import { needsUserOnboarding } from '~~/shared/auth'
|
||||
|
||||
export default defineNuxtRouteMiddleware(async (to) => {
|
||||
const auth = useAuth()
|
||||
await auth.fetchSession()
|
||||
@@ -6,7 +8,7 @@ export default defineNuxtRouteMiddleware(async (to) => {
|
||||
return navigateTo('/login')
|
||||
}
|
||||
|
||||
if (to.path !== '/security' && auth.needsOnboarding.value) {
|
||||
if (to.path !== '/security' && needsUserOnboarding(auth.user.value)) {
|
||||
return navigateTo('/security')
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { getDefaultAuthenticatedPath } from '~~/shared/auth'
|
||||
|
||||
export default defineNuxtRouteMiddleware(async () => {
|
||||
const auth = useAuth()
|
||||
await auth.fetchSession()
|
||||
@@ -6,9 +8,5 @@ export default defineNuxtRouteMiddleware(async () => {
|
||||
return
|
||||
}
|
||||
|
||||
if (auth.needsOnboarding.value) {
|
||||
return navigateTo('/security')
|
||||
}
|
||||
|
||||
return navigateTo(auth.isSuperAdmin.value ? '/management/users' : '/security')
|
||||
return navigateTo(getDefaultAuthenticatedPath(auth.user.value))
|
||||
})
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { needsUserOnboarding } from '~~/shared/auth'
|
||||
|
||||
export default defineNuxtRouteMiddleware(async () => {
|
||||
const auth = useAuth()
|
||||
await auth.fetchSession()
|
||||
@@ -6,7 +8,7 @@ export default defineNuxtRouteMiddleware(async () => {
|
||||
return navigateTo('/login')
|
||||
}
|
||||
|
||||
if (auth.needsOnboarding.value) {
|
||||
if (needsUserOnboarding(auth.user.value)) {
|
||||
return navigateTo('/security')
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user