Files
crewli/apps/portal/src/plugins/1.router/guards.ts
bert.hausmans c4a23b6763 feat: passwordless registration — defer account creation to approval
Removes password from the volunteer registration form. Account
creation is now deferred to the approval step:

Backend:
- Registration creates Person without User (user_id=null)
- On approval, system finds or creates User by person.email
- New accounts get a "set password" email with activation link
- Existing accounts get a portal link email
- Added registration_source column to persons (self/organizer)
- Fuzzy name matching skipped for self-registered persons
- person.email is always source of truth for account linking

Frontend:
- Registration form no longer collects password
- Email check shows info alert with login suggestion
- New wachtwoord-instellen.vue page for account activation
- PasswordRequirements.vue component (reused on reset page)
- Success page updated with activation messaging

Tests: 837 passed (all updated for new flow)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 03:27:47 +02:00

65 lines
2.2 KiB
TypeScript

import type { Router } from 'vue-router'
import { useAuthStore } from '@/stores/useAuthStore'
import { usePortalStore } from '@/stores/usePortalStore'
const guestOnlyPaths = ['/login', '/wachtwoord-vergeten', '/wachtwoord-resetten', '/wachtwoord-instellen', '/verify-email-change']
// Old dashboard routes that need backward-compat redirects
const dashboardRedirects: Record<string, string> = {
'/dashboard': '/evenementen',
'/dashboard/my-shifts': '/evenementen',
'/dashboard/claim-shifts': '/evenementen',
}
export function setupGuards(router: Router) {
router.beforeEach(async (to, from) => {
const authStore = useAuthStore()
if (!authStore.isInitialized) {
await authStore.initialize()
}
if (import.meta.env.DEV) {
console.log('🔒 Router Guard:', {
to: to.path,
from: from.path,
isAuthenticated: authStore.isAuthenticated,
})
}
// Hydrate portal data once after auth is confirmed
if (authStore.isAuthenticated) {
const portalStore = usePortalStore()
await portalStore.hydrateIfNeeded()
}
// Backward-compat redirects for old dashboard routes
const redirect = dashboardRedirects[to.path]
if (redirect && authStore.isAuthenticated) {
if (import.meta.env.DEV) console.log('🔄 Backward-compat redirect:', to.path, '→', redirect)
return { path: redirect }
}
const requiresAuth = to.meta.requiresAuth === true
// Public routes — no auth check needed
if (!requiresAuth) {
if (authStore.isAuthenticated && guestOnlyPaths.some(p => to.path === p || to.path.startsWith(`${p}/`))) {
if (import.meta.env.DEV) console.log('🔄 Redirecting logged-in user away from login page')
return { path: '/evenementen' }
}
if (import.meta.env.DEV) console.log('✅ Public route, allowing access')
return
}
// Auth required — redirect to login if not authenticated
if (!authStore.isAuthenticated) {
if (import.meta.env.DEV) console.log('🚫 Not authenticated, redirecting to login')
return { path: '/login', query: { to: to.fullPath } }
}
if (import.meta.env.DEV) console.log('✅ Access granted')
})
}