From fcd72e1f9813cf54b6cbef264994db4d1d429db5 Mon Sep 17 00:00:00 2001 From: Steven Date: Tue, 11 Jul 2023 23:39:19 +0800 Subject: [PATCH] chore: update auth checks --- web/src/components/Header.tsx | 2 ++ web/src/pages/SignIn.tsx | 6 +++++- web/src/pages/SignUp.tsx | 10 ++++++---- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/web/src/components/Header.tsx b/web/src/components/Header.tsx index 1b99c8f..fb98a41 100644 --- a/web/src/components/Header.tsx +++ b/web/src/components/Header.tsx @@ -1,6 +1,7 @@ import { Avatar } from "@mui/joy"; import { useState } from "react"; import { Link, useNavigate } from "react-router-dom"; +import * as api from "../helpers/api"; import useUserStore from "../stores/v1/user"; import Icon from "./Icon"; import Dropdown from "./common/Dropdown"; @@ -12,6 +13,7 @@ const Header: React.FC = () => { const [showAboutDialog, setShowAboutDialog] = useState(false); const handleSignOutButtonClick = async () => { + await api.signout(); navigate("/auth"); }; diff --git a/web/src/pages/SignIn.tsx b/web/src/pages/SignIn.tsx index 0e4fcc9..fb8e966 100644 --- a/web/src/pages/SignIn.tsx +++ b/web/src/pages/SignIn.tsx @@ -19,7 +19,11 @@ const SignIn: React.FC = () => { const allowConfirm = email.length > 0 && password.length > 0; useEffect(() => { - api.signout(); + if (userStore.getCurrentUser()) { + return navigate("/", { + replace: true, + }); + } }, []); const handleEmailInputChanged = (e: React.ChangeEvent) => { diff --git a/web/src/pages/SignUp.tsx b/web/src/pages/SignUp.tsx index 065af24..cc7bafe 100644 --- a/web/src/pages/SignUp.tsx +++ b/web/src/pages/SignUp.tsx @@ -20,6 +20,12 @@ const SignUp: React.FC = () => { const allowConfirm = email.length > 0 && nickname.length > 0 && password.length > 0; useEffect(() => { + if (userStore.getCurrentUser()) { + return navigate("/", { + replace: true, + }); + } + if (disallowSignUp) { return navigate("/auth", { replace: true, @@ -27,10 +33,6 @@ const SignUp: React.FC = () => { } }, []); - useEffect(() => { - api.signout(); - }, []); - const handleEmailInputChanged = (e: React.ChangeEvent) => { const text = e.target.value as string; setEmail(text);