2026-01-28 16:18:20 +01:00
|
|
|
import { useAuth } from '../composables/useAuth';
|
|
|
|
|
|
2026-02-27 23:28:52 +01:00
|
|
|
/**
|
|
|
|
|
* Authentication plugin that initializes auth state on app mount (client-side only).
|
|
|
|
|
*
|
|
|
|
|
* This plugin automatically:
|
|
|
|
|
* - Restores the user session from Pocketbase's authStore on page load
|
|
|
|
|
* - Sets up cross-tab synchronization via Pocketbase's onChange listener
|
|
|
|
|
* - Enables session persistence across page refreshes
|
|
|
|
|
*
|
|
|
|
|
* **Lifecycle**: Runs once on app mount, before any pages are rendered.
|
|
|
|
|
*
|
|
|
|
|
* **Cross-Tab Sync**: When a user logs in or out in one browser tab, all other tabs
|
|
|
|
|
* automatically update their auth state within ~2 seconds (handled by Pocketbase SDK).
|
|
|
|
|
*
|
|
|
|
|
* **Session Restoration**: On page refresh, the plugin checks Pocketbase's authStore
|
|
|
|
|
* and restores the user object if a valid session exists.
|
|
|
|
|
*
|
|
|
|
|
* @see {@link useAuth} for the auth composable API
|
|
|
|
|
*/
|
2026-01-28 16:18:20 +01:00
|
|
|
export default defineNuxtPlugin(() => {
|
|
|
|
|
const { initAuth } = useAuth();
|
|
|
|
|
initAuth();
|
|
|
|
|
});
|