Refactor auth hooks and add database existence check during migrations

- Consolidated `useAuthStore` into the unified `useAuth` hook for cleaner imports and consistency across frontend components.
- Enhanced database management in Alembic migrations by introducing `ensure_database_exists` to automatically create the database if missing.
This commit is contained in:
Felipe Cardoso
2025-11-03 13:16:34 +01:00
parent 2ee48bf3fa
commit 9843cf8218
3 changed files with 55 additions and 6 deletions

View File

@@ -8,7 +8,7 @@
import { useEffect, useState } from 'react';
import { useRouter, usePathname } from 'next/navigation';
import { useAuthStore } from '@/lib/stores/authStore';
import { useAuth } from '@/lib/stores';
import { useMe } from '@/lib/api/hooks/useAuth';
import { AuthLoadingSkeleton } from '@/components/layout';
import config from '@/config/app.config';
@@ -50,7 +50,7 @@ interface AuthGuardProps {
export function AuthGuard({ children, requireAdmin = false, fallback }: AuthGuardProps) {
const router = useRouter();
const pathname = usePathname();
const { isAuthenticated, isLoading: authLoading, user } = useAuthStore();
const { isAuthenticated, isLoading: authLoading, user } = useAuth();
// Delayed loading state - only show skeleton after 150ms to avoid flicker on fast loads
const [showLoading, setShowLoading] = useState(false);

View File

@@ -8,7 +8,7 @@
import Link from 'next/link';
import { usePathname } from 'next/navigation';
import { useAuthStore } from '@/lib/stores/authStore';
import { useAuth } from '@/lib/stores';
import { useLogout } from '@/lib/api/hooks/useAuth';
import {
DropdownMenu,
@@ -67,7 +67,7 @@ function NavLink({
}
export function Header() {
const { user } = useAuthStore();
const { user } = useAuth();
const { mutate: logout, isPending: isLoggingOut } = useLogout();
const handleLogout = () => {