Migrate auth hooks to AuthContext and update tests for compatibility

- Refactored `useIsAuthenticated` and `useCurrentUser` to use `useAuth` from `AuthContext` instead of `useAuthStore`.
- Updated test setups to inject `AuthProvider` with mocked store hooks for improved test isolation and consistency.
- Replaced legacy `useAuthStore` mocks with `AuthContext`-compatible implementations in affected tests.
This commit is contained in:
Felipe Cardoso
2025-11-03 14:27:25 +01:00
parent 532577f36c
commit 852c7eceff
3 changed files with 53 additions and 19 deletions

View File

@@ -22,6 +22,7 @@ import {
} from '../client';
import { useAuthStore } from '@/lib/stores/authStore';
import type { User } from '@/lib/stores/authStore';
import { useAuth } from '@/lib/auth/AuthContext';
import { parseAPIError, getGeneralError } from '../errors';
import { isTokenWithUser } from '../types';
import config from '@/config/app.config';
@@ -481,7 +482,7 @@ export function usePasswordChange(onSuccess?: (message: string) => void) {
* @returns boolean indicating authentication status
*/
export function useIsAuthenticated(): boolean {
return useAuthStore((state) => state.isAuthenticated);
return useAuth((state) => state.isAuthenticated);
}
/**
@@ -489,7 +490,7 @@ export function useIsAuthenticated(): boolean {
* @returns Current user or null
*/
export function useCurrentUser(): User | null {
return useAuthStore((state) => state.user);
return useAuth((state) => state.user);
}
/**