Initial commit
This commit is contained in:
10
app/middleware/00.fetchUser.global.ts
Normal file
10
app/middleware/00.fetchUser.global.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
/**
|
||||
* Middleware to refresh the authenticated user if possible
|
||||
* Executed on all route changes
|
||||
*/
|
||||
export default defineNuxtRouteMiddleware(async () => {
|
||||
if (!useUser().isAuthenticated || useUser().user === null) {
|
||||
// Attempt to refresh the auth store
|
||||
await useUser().authRefresh()
|
||||
}
|
||||
})
|
||||
10
app/middleware/auth.ts
Normal file
10
app/middleware/auth.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
/**
|
||||
* Middleware to protect routes that require authentication.
|
||||
* Redirects to the login page if the user is not authenticated.
|
||||
*/
|
||||
export default defineNuxtRouteMiddleware(async () => {
|
||||
if (!useUser().isAuthenticated) {
|
||||
// If still not authenticated, redirect to login
|
||||
return navigateTo('/login')
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user