mirror of https://github.com/usememos/memos
chore: fix auth status checks
parent
fa6693a7ae
commit
33dda9bf87
@ -0,0 +1,27 @@
|
||||
import { useEffect } from "react";
|
||||
import useCurrentUser from "@/hooks/useCurrentUser";
|
||||
import useNavigateTo from "@/hooks/useNavigateTo";
|
||||
|
||||
interface Props {
|
||||
children: React.ReactNode;
|
||||
}
|
||||
|
||||
const AuthStatusProvider = (props: Props) => {
|
||||
const navigateTo = useNavigateTo();
|
||||
const currentUser = useCurrentUser();
|
||||
|
||||
useEffect(() => {
|
||||
if (!currentUser) {
|
||||
// If not logged in, redirect to explore page by default.
|
||||
navigateTo("/explore");
|
||||
}
|
||||
}, []);
|
||||
|
||||
if (!currentUser) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return <>{props.children}</>;
|
||||
};
|
||||
|
||||
export default AuthStatusProvider;
|
Loading…
Reference in New Issue