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