mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-02-10 19:44:23 +01:00
25 lines
541 B
TypeScript
25 lines
541 B
TypeScript
|
|
import { useEffect } from 'react';
|
||
|
|
import { useNavigate } from 'react-router-dom';
|
||
|
|
import { useAuthContext } from '~/hooks';
|
||
|
|
|
||
|
|
export default function useAuthRedirect() {
|
||
|
|
const { isAuthenticated } = useAuthContext();
|
||
|
|
const navigate = useNavigate();
|
||
|
|
|
||
|
|
useEffect(() => {
|
||
|
|
const timeout = setTimeout(() => {
|
||
|
|
if (!isAuthenticated) {
|
||
|
|
navigate('/login', { replace: true });
|
||
|
|
}
|
||
|
|
}, 300);
|
||
|
|
|
||
|
|
return () => {
|
||
|
|
clearTimeout(timeout);
|
||
|
|
};
|
||
|
|
}, [isAuthenticated, navigate]);
|
||
|
|
|
||
|
|
return {
|
||
|
|
isAuthenticated,
|
||
|
|
};
|
||
|
|
}
|