Fixed login bug again
This commit is contained in:
parent
6bb0f0dd0a
commit
0d214de5ed
21 changed files with 1142 additions and 1147 deletions
|
|
@ -1,9 +1,7 @@
|
|||
import { useEffect, useState, type ReactNode } from "react";
|
||||
import { useNavigate } from "@tanstack/react-router";
|
||||
import { type ReactNode } from "react";
|
||||
|
||||
import Sidebar from "@/components/sidebar";
|
||||
import Navbar from "@/components/navbar";
|
||||
import { useStorage } from "@tensamin/storage/context";
|
||||
|
||||
import { motion } from "framer-motion";
|
||||
|
||||
|
|
@ -13,40 +11,6 @@ import { motion } from "framer-motion";
|
|||
* @returns unknown.
|
||||
*/
|
||||
export default function Layout(props: { children: ReactNode }) {
|
||||
const [loggedIn, setLoggedIn] = useState<boolean | null>(null);
|
||||
|
||||
const { load } = useStorage();
|
||||
|
||||
const navigate = useNavigate();
|
||||
|
||||
useEffect(() => {
|
||||
let active = true;
|
||||
|
||||
void load("user_id").then((userId) => {
|
||||
if (!active) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (userId !== 0) {
|
||||
setLoggedIn(true);
|
||||
return;
|
||||
}
|
||||
|
||||
setLoggedIn(false);
|
||||
void navigate({
|
||||
to: "/login",
|
||||
});
|
||||
});
|
||||
|
||||
return () => {
|
||||
active = false;
|
||||
};
|
||||
}, [load, navigate]);
|
||||
|
||||
if (loggedIn !== true) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<motion.div
|
||||
className="w-full h-full flex bg-sidebar"
|
||||
|
|
|
|||
Loading…
Reference in a new issue