Fix redirect loops and SSR hydration issues in auth flow
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:
2025-08-07 17:21:18 +02:00
parent 423d8c3aa1
commit c6a57c7922
5 changed files with 276 additions and 39 deletions

View File

@@ -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);