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:
@@ -14,8 +14,10 @@ const app = createApp(App)
|
||||
|
||||
// Error handler for unhandled errors
|
||||
app.config.errorHandler = (err, instance, info) => {
|
||||
console.error('Vue Error:', err, info)
|
||||
console.error('Component:', instance)
|
||||
if (import.meta.env.DEV) {
|
||||
console.error('Vue Error:', err, info)
|
||||
console.error('Component:', instance)
|
||||
}
|
||||
}
|
||||
|
||||
// Register plugins
|
||||
@@ -24,7 +26,7 @@ app.use(VueQueryPlugin, queryClientConfig)
|
||||
try {
|
||||
registerPlugins(app)
|
||||
} catch (error) {
|
||||
console.error('Failed to register plugins:', error)
|
||||
if (import.meta.env.DEV) console.error('Failed to register plugins:', error)
|
||||
throw error
|
||||
}
|
||||
|
||||
@@ -32,7 +34,7 @@ try {
|
||||
try {
|
||||
app.mount('#app')
|
||||
} catch (error) {
|
||||
console.error('Failed to mount app:', error)
|
||||
if (import.meta.env.DEV) console.error('Failed to mount app:', error)
|
||||
// Show error message to user (safe DOM construction — no innerHTML with variables)
|
||||
const el = document.getElementById('app')!
|
||||
el.innerHTML = ''
|
||||
|
||||
@@ -31,7 +31,7 @@ watch([page, itemsPerPage], async () => {
|
||||
})
|
||||
}
|
||||
catch (err) {
|
||||
console.error('Failed to fetch events:', err)
|
||||
if (import.meta.env.DEV) console.error('Failed to fetch events:', err)
|
||||
}
|
||||
}, { immediate: true })
|
||||
|
||||
@@ -44,7 +44,7 @@ watch(organisationId, async (id) => {
|
||||
})
|
||||
}
|
||||
catch (err) {
|
||||
console.error('Failed to fetch events:', err)
|
||||
if (import.meta.env.DEV) console.error('Failed to fetch events:', err)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -96,7 +96,7 @@ const login = async () => {
|
||||
router.replace(rawTo.startsWith('/') ? rawTo : '/')
|
||||
}
|
||||
catch (err) {
|
||||
console.error(err)
|
||||
if (import.meta.env.DEV) console.error(err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ const fetchFaqs = async () => {
|
||||
query: {
|
||||
q: faqSearchQuery.value,
|
||||
},
|
||||
}).catch(err => console.log(err))
|
||||
}).catch(err => { if (import.meta.env.DEV) console.log(err) })
|
||||
|
||||
faqs.value = data
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ const register = async () => {
|
||||
})
|
||||
}
|
||||
catch (err) {
|
||||
console.error(err)
|
||||
if (import.meta.env.DEV) console.error(err)
|
||||
}
|
||||
finally {
|
||||
isLoading.value = false
|
||||
|
||||
@@ -65,7 +65,7 @@ const createDealData = ref<CreateDealData>({
|
||||
})
|
||||
|
||||
const onSubmit = () => {
|
||||
console.log('createDealData :>> ', createDealData.value)
|
||||
if (import.meta.env.DEV) console.log('createDealData :>> ', createDealData.value)
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
@@ -90,7 +90,7 @@ const propertyListingData = ref<PropertyListingData>({
|
||||
const currentStep = ref(0)
|
||||
|
||||
const onSubmit = () => {
|
||||
console.log('propertyListingData :>> ', propertyListingData.value)
|
||||
if (import.meta.env.DEV) console.log('propertyListingData :>> ', propertyListingData.value)
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
@@ -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')
|
||||
})
|
||||
}
|
||||
|
||||
@@ -12,13 +12,21 @@ const dashboardRedirects: Record<string, string> = {
|
||||
}
|
||||
|
||||
export function setupGuards(router: Router) {
|
||||
router.beforeEach(async (to) => {
|
||||
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()
|
||||
@@ -28,6 +36,7 @@ export function setupGuards(router: Router) {
|
||||
// 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 }
|
||||
}
|
||||
|
||||
@@ -36,15 +45,20 @@ export function setupGuards(router: Router) {
|
||||
// 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')
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user