feat(FE) : implementasi hak akses
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
// 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);
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user