Website Structure
This commit is contained in:
parent
62812f2090
commit
71f0676a62
22365 changed files with 4265753 additions and 791 deletions
28
Frontend-Learner/middleware/auth.ts
Normal file
28
Frontend-Learner/middleware/auth.ts
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
export default defineNuxtRouteMiddleware((to) => {
|
||||
const { isAuthenticated } = useAuth()
|
||||
|
||||
// Pages that are accessible only when NOT logged in (Auth pages)
|
||||
const authPages = [
|
||||
'/auth/login',
|
||||
'/auth/register',
|
||||
'/auth/forgot-password',
|
||||
'/auth/reset-password'
|
||||
]
|
||||
|
||||
// Pages that are accessible as public landing
|
||||
// Note: /courses and /discovery (now in browse/) might be public depending on logic,
|
||||
// but let's assume browse pages are public or handled separately.
|
||||
// For now, we list the root.
|
||||
const publicPages = ['/', '/courses', '/browse', '/browse/discovery']
|
||||
|
||||
// 1. If user is authenticated and tries to access login/register (Keep landing page accessible)
|
||||
if (isAuthenticated.value && authPages.includes(to.path)) {
|
||||
return navigateTo('/dashboard', { replace: true })
|
||||
}
|
||||
|
||||
// 2. If user is NOT authenticated and tries to access a page that has this middleware applied
|
||||
// and is NOT one of the public or auth pages.
|
||||
if (!isAuthenticated.value && !authPages.includes(to.path) && !publicPages.includes(to.path)) {
|
||||
return navigateTo('/auth/login', { replace: true })
|
||||
}
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue