chore: standardize dev-only debug logging across all three SPAs
Router guards: - apps/app: added DEV-gated logging matching admin pattern (route info, auth decisions, org selection, access granted/denied) - apps/portal: added DEV-gated logging matching admin pattern (route info, auth decisions, backward-compat redirects) - apps/admin: already had full logging (unchanged) Ungated console statements fixed: - admin/main.ts: error handler, plugin registration, mount errors - admin/pages/login.vue, register.vue: catch block errors - admin/pages/events/index.vue: fetch error logging - admin/pages/wizard-examples: demo form submit logging - admin/pages/faq.vue: catch block error All console statements in Crewli-authored code are now gated behind import.meta.env.DEV — zero console output in production builds. Vuexy template demo files (views/demos/*) left as-is. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -3,7 +3,7 @@ import { useAuthStore } from '@/stores/useAuthStore'
|
||||
import { useOrganisationStore } from '@/stores/useOrganisationStore'
|
||||
|
||||
export function setupGuards(router: Router) {
|
||||
router.beforeEach(async (to) => {
|
||||
router.beforeEach(async (to, from) => {
|
||||
const authStore = useAuthStore()
|
||||
|
||||
// Wait for initialization to complete (only blocks on first navigation)
|
||||
@@ -11,24 +11,36 @@ export function setupGuards(router: Router) {
|
||||
await authStore.initialize()
|
||||
}
|
||||
|
||||
if (import.meta.env.DEV) {
|
||||
console.log('🔒 Router Guard:', {
|
||||
to: to.path,
|
||||
from: from.path,
|
||||
isAuthenticated: authStore.isAuthenticated,
|
||||
})
|
||||
}
|
||||
|
||||
const isPublic = to.meta.public === true
|
||||
|
||||
// Allow public routes (login, auth pages, 404) — but redirect authenticated users away from login
|
||||
if (isPublic) {
|
||||
const guestOnlyPaths = ['/login', '/forgot-password', '/reset-password', '/verify-email-change']
|
||||
if (authStore.isAuthenticated && guestOnlyPaths.some(p => to.path === p)) {
|
||||
if (import.meta.env.DEV) console.log('🔄 Redirecting logged-in user away from login page')
|
||||
return { name: 'dashboard' }
|
||||
}
|
||||
if (import.meta.env.DEV) console.log('✅ Public route, allowing access')
|
||||
return
|
||||
}
|
||||
|
||||
// Routes that opt out of auth (e.g. invitations)
|
||||
if (to.meta.requiresAuth === false) {
|
||||
if (import.meta.env.DEV) console.log('✅ Route does not require auth')
|
||||
return
|
||||
}
|
||||
|
||||
// Not authenticated → redirect to login with return URL
|
||||
if (!authStore.isAuthenticated) {
|
||||
if (import.meta.env.DEV) console.log('🚫 Not authenticated, redirecting to login')
|
||||
return { path: '/login', query: { to: to.fullPath } }
|
||||
}
|
||||
|
||||
@@ -37,13 +49,16 @@ export function setupGuards(router: Router) {
|
||||
const isSelectOrgPage = to.path === '/select-organisation'
|
||||
|
||||
if (isSelectOrgPage) {
|
||||
// Already on the org selection page — allow
|
||||
if (import.meta.env.DEV) console.log('✅ Organisation selection page')
|
||||
return
|
||||
}
|
||||
|
||||
// If user has organisations but none selected → redirect to selection
|
||||
if (authStore.organisations.length > 0 && !orgStore.hasOrganisation) {
|
||||
if (import.meta.env.DEV) console.log('🔄 No organisation selected, redirecting')
|
||||
return { path: '/select-organisation' }
|
||||
}
|
||||
|
||||
if (import.meta.env.DEV) console.log('✅ Access granted')
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user