This commit is contained in:
2025-11-23 00:11:18 +01:00
parent 014f489857
commit 85afff2c19
12 changed files with 34 additions and 179 deletions
@@ -8,14 +8,11 @@ type AppDispatch = (action: { type: string; [key: string]: unknown }) => void;
type SetStatusMessage = (message: string, variant?: string) => void;
type SetLoading = (state: boolean) => void;
interface UseAuthManagerArgs {
token?: string | null;
appStatus: AppStatus;
appDispatch: AppDispatch;
setStatusMessage: SetStatusMessage;
setLoading: SetLoading;
}
interface UseAuthManagerResult {
@@ -29,7 +26,6 @@ const useAuthManager = ({
appStatus,
appDispatch,
setStatusMessage,
setLoading,
}: UseAuthManagerArgs): UseAuthManagerResult => {
const tokenRef = useRef<string | null>(token);
const initialRefreshAttemptedRef = useRef(Boolean(token));
@@ -71,17 +67,15 @@ const useAuthManager = ({
const handleLogout = useCallback(async () => {
try {
setLoading(true);
await logoutSession();
} catch (error) {
console.warn('[Auth] Failed to revoke refresh token during logout', error);
} finally {
clearAuthToken();
setLoading(false);
appDispatch({ type: 'LOGOUT' });
setStatusMessage('Logged out.', 'info');
}
}, [appDispatch, setLoading, setStatusMessage]);
}, [appDispatch, setStatusMessage]);
return { tokenRef, refreshAccessToken, handleLogout };
};