Files
antrean-operasi/plugins/auth.client.ts
2026-02-27 13:26:52 +07:00

28 lines
755 B
TypeScript
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// plugins/auth.client.ts
// This plugin initializes authentication state once on app load
// Runs only on client-side before any components mount
export default defineNuxtPlugin({
name: 'auth',
enforce: 'pre', // Run before other plugins
async setup(nuxtApp) {
const { checkAuth, user } = useAuth();
try {
// Initialize auth state once on app load
// This MUST complete before app renders
const userData = await checkAuth();
if (userData) {
console.log('✅ Auth plugin: User authenticated');
} else {
console.log(' Auth plugin: No active session');
}
} catch (err) {
console.error('❌ Auth plugin: Failed to initialize auth:', err);
}
}
});