mirror of
https://github.com/lemeow125/Ivy-Frontend.git
synced 2025-05-14 18:41:06 +08:00
Separated session checker and page login verifier into components
This commit is contained in:
parent
b12f205efd
commit
c3ae196b6c
10 changed files with 101 additions and 65 deletions
|
@ -8,30 +8,16 @@ import { SetUser } from "../../Features/Redux/Slices/LoggedInUserSlice/LoggedInU
|
|||
import { useDispatch, useSelector } from "react-redux";
|
||||
import { LoginState } from "../../Interfaces/Interfaces";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import PreviousSessionChecker from "../PreviousSessionChecker/PreviousSessionChecker";
|
||||
|
||||
export interface props {
|
||||
children: React.ReactNode;
|
||||
}
|
||||
|
||||
export default function Container(props: props) {
|
||||
const dispatch = useDispatch();
|
||||
const navigate = useNavigate();
|
||||
const logged_in = useSelector((state: LoginState) => state.logged_in.value);
|
||||
// Function to check for previous login session
|
||||
async function CheckPreviousSession() {
|
||||
if (await CheckSavedSession()) {
|
||||
if (logged_in !== true) {
|
||||
await dispatch(toggle_login());
|
||||
await dispatch(SetUser(await UserInfo()));
|
||||
}
|
||||
}
|
||||
}
|
||||
useEffect(() => {
|
||||
CheckPreviousSession();
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div>
|
||||
<PreviousSessionChecker />
|
||||
<Header />
|
||||
<div style={{ width: "15%", position: "fixed" }}>
|
||||
<Sidebar />
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue