Fix redirect loops and SSR hydration issues in auth flow
All checks were successful
Build And Push Image / docker (push) Successful in 2m59s
All checks were successful
Build And Push Image / docker (push) Successful in 2m59s
- Replace ref with useState in useAuth for SSR compatibility - Move navigation logic from top-level to onMounted hooks - Add guest middleware to login page to prevent auth conflicts - Simplify dashboard auth checks by relying on middleware - Add loading state to index page during auth resolution This prevents infinite redirect loops and hydration mismatches that occurred during server-side rendering when navigating between authenticated and unauthenticated states.
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
import type { User } from '~/utils/types';
|
||||
|
||||
export const useAuth = () => {
|
||||
const user = ref<User | null>(null);
|
||||
// Use useState for SSR compatibility - prevents hydration mismatches
|
||||
const user = useState<User | null>('auth.user', () => null);
|
||||
const isAuthenticated = computed(() => !!user.value);
|
||||
const loading = ref(false);
|
||||
const error = ref<string | null>(null);
|
||||
|
||||
Reference in New Issue
Block a user