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
19 lines
388 B
TypeScript
19 lines
388 B
TypeScript
import { needsUserOnboarding } from '~~/shared/auth'
|
|
|
|
export default defineNuxtRouteMiddleware(async () => {
|
|
const auth = useAuth()
|
|
await auth.fetchSession()
|
|
|
|
if (!auth.user.value) {
|
|
return navigateTo('/login')
|
|
}
|
|
|
|
if (needsUserOnboarding(auth.user.value)) {
|
|
return navigateTo('/security')
|
|
}
|
|
|
|
if (!auth.isSuperAdmin.value) {
|
|
return navigateTo('/security')
|
|
}
|
|
})
|