Files
imphnen-frontend-service/libs/utils/src/hooks/use-session.ts
T

22 lines
513 B
TypeScript
Raw Normal View History

2025-11-25 01:47:56 +07:00
import { supabase } from '@imphnen-frontend-service/service';
2025-05-23 00:28:29 +07:00
import { useAuthStore } from './';
import { useNavigate } from 'react-router';
2025-04-03 12:21:10 +07:00
export const useSession = () => {
2025-05-23 00:28:29 +07:00
const navigate = useNavigate();
2025-11-25 01:47:56 +07:00
const { clearSession, session, status } = useAuthStore();
2025-05-27 01:41:13 +07:00
const isAuthenticated = status === 'authenticated';
2025-11-25 01:47:56 +07:00
const signOut = async () => {
await supabase.auth.signOut();
2025-05-23 00:28:29 +07:00
clearSession();
2025-11-25 01:47:56 +07:00
navigate('/auth/login');
2025-04-03 12:21:10 +07:00
};
2025-11-25 01:47:56 +07:00
2025-04-03 12:21:10 +07:00
return {
session,
signOut,
2025-05-27 01:41:13 +07:00
isAuthenticated,
2025-04-03 12:21:10 +07:00
};
};