2026-09-03 18:12:31 +01:00
|
|
|
import { createRouter, createWebHistory } from 'vue-router'
|
|
|
|
|
import { useAuthStore } from '../stores/auth'
|
|
|
|
|
|
|
|
|
|
const router = createRouter({
|
|
|
|
|
history: createWebHistory(import.meta.env.BASE_URL),
|
|
|
|
|
routes: [
|
|
|
|
|
{
|
|
|
|
|
path: '/',
|
|
|
|
|
name: 'home',
|
|
|
|
|
component: () => import('../views/HomeView.vue'),
|
|
|
|
|
meta: { requiresAuth: true },
|
|
|
|
|
},
|
2026-09-03 18:59:51 +01:00
|
|
|
{
|
2026-09-04 11:28:59 +01:00
|
|
|
path: '/projects/:id(\\d+)',
|
|
|
|
|
name: 'project',
|
|
|
|
|
component: () => import('../views/ProjectView.vue'),
|
2026-09-03 18:59:51 +01:00
|
|
|
meta: { requiresAuth: true },
|
|
|
|
|
},
|
2026-09-03 20:04:49 +01:00
|
|
|
{
|
|
|
|
|
path: '/profile',
|
|
|
|
|
name: 'profile',
|
|
|
|
|
component: () => import('../views/ProfileView.vue'),
|
|
|
|
|
meta: { requiresAuth: true },
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
// Magic-link target. Works signed in or out — verifying returns a session.
|
|
|
|
|
path: '/verify-email',
|
|
|
|
|
name: 'verify-email',
|
|
|
|
|
component: () => import('../views/VerifyEmailView.vue'),
|
|
|
|
|
},
|
2026-09-03 18:12:31 +01:00
|
|
|
{
|
|
|
|
|
path: '/login',
|
|
|
|
|
name: 'login',
|
|
|
|
|
component: () => import('../views/LoginView.vue'),
|
|
|
|
|
meta: { guestOnly: true },
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: '/register',
|
|
|
|
|
name: 'register',
|
|
|
|
|
component: () => import('../views/RegisterView.vue'),
|
|
|
|
|
meta: { guestOnly: true },
|
|
|
|
|
},
|
|
|
|
|
{ path: '/:pathMatch(.*)*', redirect: { name: 'home' } },
|
|
|
|
|
],
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
router.beforeEach((to) => {
|
|
|
|
|
const auth = useAuthStore()
|
|
|
|
|
|
|
|
|
|
if (to.meta.requiresAuth && !auth.isAuthenticated) {
|
|
|
|
|
return {
|
|
|
|
|
name: 'login',
|
|
|
|
|
query: to.fullPath === '/' ? {} : { redirect: to.fullPath },
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (to.meta.guestOnly && auth.isAuthenticated) {
|
|
|
|
|
return { name: 'home' }
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
export default router
|