/** * Creates a navigation guard to redirect authenticated users away from auth pages * * @example * ```ts * import { createAuthGuard } from '@bagelink/auth' * * router.beforeEach(createAuthGuard({ redirectTo: '/dashboard' })) * ``` */ export function createAuthGuard(config: { redirectTo?: string } = {}) { const { redirectTo = '/' } = config return async (to: any, _: any) => { // Import dynamically to avoid circular dependencies const { useAuth } = await import('./useAuth') const { user } = useAuth() // If route doesn't require auth and user is authenticated, redirect if (to.meta.requiresAuth === false && user.value) { return redirectTo } return true } }