Added individual product views and fixed login session checker

This commit is contained in:
Keannu Christian Bernasol 2023-03-06 13:59:16 +08:00
parent f411ea00a4
commit 48ed8f45c6
8 changed files with 83 additions and 26 deletions

View file

@ -5,7 +5,8 @@ import styles from "../../styles";
import { CheckSavedSession, UserInfo } from "../Api/Api";
import { toggle_login } from "../../Features/Redux/Slices/Login/LoginSlice";
import { SetUser } from "../../Features/Redux/Slices/LoggedInUserSlice/LoggedInUserSlice";
import { useDispatch } from "react-redux";
import { useDispatch, useSelector } from "react-redux";
import { LoginState } from "../../Interfaces/Interfaces";
export interface props {
children: React.ReactNode;
@ -13,11 +14,14 @@ export interface props {
export default function Container(props: props) {
const dispatch = useDispatch();
const logged_in = useSelector((state: LoginState) => state.logged_in.value);
// Function to check for previous login session
async function CheckPreviousSession() {
if (await CheckSavedSession()) {
await dispatch(toggle_login());
await dispatch(SetUser(await UserInfo()));
if (logged_in !== true) {
await dispatch(toggle_login());
await dispatch(SetUser(await UserInfo()));
}
}
}
useEffect(() => {