refactor: Transition to authentication system and remove identity management
- Replace identity management with a new authentication system across the application. - Update App.vue to integrate LoginDialog and remove PasswordDialog. - Modify Navbar.vue to handle user authentication state and logout functionality. - Enhance Home.vue to display user information upon login. - Implement routing changes in index.ts to enforce authentication requirements for protected routes.
This commit is contained in:
parent
5ceb12ca3b
commit
be4ab13b32
11 changed files with 1065 additions and 96 deletions
|
|
@ -1,5 +1,7 @@
|
|||
import { createRouter, createWebHistory } from 'vue-router'
|
||||
import { auth } from '@/composables/useAuth'
|
||||
import Home from '@/pages/Home.vue'
|
||||
import Login from '@/pages/Login.vue'
|
||||
|
||||
const router = createRouter({
|
||||
history: createWebHistory(),
|
||||
|
|
@ -7,17 +9,47 @@ const router = createRouter({
|
|||
{
|
||||
path: '/',
|
||||
name: 'home',
|
||||
component: Home
|
||||
component: Home,
|
||||
meta: {
|
||||
requiresAuth: true
|
||||
}
|
||||
},
|
||||
{
|
||||
path: '/login',
|
||||
name: 'login',
|
||||
component: Login,
|
||||
meta: {
|
||||
requiresAuth: false
|
||||
}
|
||||
},
|
||||
{
|
||||
path: '/events',
|
||||
name: 'events',
|
||||
component: () => import('@/pages/events.vue'),
|
||||
meta: {
|
||||
title: 'Events'
|
||||
title: 'Events',
|
||||
requiresAuth: true
|
||||
}
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
// Navigation guard to check authentication
|
||||
router.beforeEach(async (to, _from, next) => {
|
||||
// Initialize auth if not already done
|
||||
if (!auth.isAuthenticated.value && auth.checkAuth()) {
|
||||
await auth.initialize()
|
||||
}
|
||||
|
||||
if (to.meta.requiresAuth && !auth.isAuthenticated.value) {
|
||||
// Redirect to login if authentication is required but user is not authenticated
|
||||
next('/login')
|
||||
} else if (to.path === '/login' && auth.isAuthenticated.value) {
|
||||
// Redirect to home if user is already authenticated and trying to access login
|
||||
next('/')
|
||||
} else {
|
||||
next()
|
||||
}
|
||||
})
|
||||
|
||||
export default router
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue