From 5080a68dd4e74643a6f0d71faf2abb40a9167895 Mon Sep 17 00:00:00 2001 From: Shubham-Lal Date: Mon, 8 Apr 2024 10:27:30 +0530 Subject: [PATCH] client: show auth modal on authenticating --- client/src/components/modal/login-tab.tsx | 4 ++-- client/src/components/modal/signup-tab.tsx | 13 ++++++++++--- client/src/pages/auth/index.tsx | 8 +++++--- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/client/src/components/modal/login-tab.tsx b/client/src/components/modal/login-tab.tsx index 522b159..674dc8a 100644 --- a/client/src/components/modal/login-tab.tsx +++ b/client/src/components/modal/login-tab.tsx @@ -122,7 +122,7 @@ const LoginTab = () => { />
@@ -135,7 +135,7 @@ const LoginTab = () => { className='google-btn' onClick={() => window.location.href = `${import.meta.env.VITE_SERVER_URL}/api/auth/google`} > - {!loginData.id && !loginData.password && isAuthenticated === AuthStatus.Authenticating ? ( + {isAuthenticated === AuthStatus.Authenticating ? ( ) : ( <> diff --git a/client/src/components/modal/signup-tab.tsx b/client/src/components/modal/signup-tab.tsx index d313e9d..87cde9f 100644 --- a/client/src/components/modal/signup-tab.tsx +++ b/client/src/components/modal/signup-tab.tsx @@ -3,6 +3,7 @@ import { RegisterDataProps } from "../../types"; import { AuthStatus, AuthTab, useAuthStore, useTempStore } from "../../store/useAuthStore"; import { toast } from "sonner"; import { FcGoogle } from "react-icons/fc"; +import { LoadingSVG } from "../loading/svg"; const SignupTab: React.FC = ({ registerData, setRegisterData }) => { const { setAuthTab, isAuthenticated } = useAuthStore(); @@ -91,7 +92,7 @@ const SignupTab: React.FC = ({ registerData, setRegisterData />
{!tempUser.email && ( @@ -106,8 +107,14 @@ const SignupTab: React.FC = ({ registerData, setRegisterData className='google-btn' onClick={() => window.location.href = `${import.meta.env.VITE_SERVER_URL}/api/auth/google`} > - - Continue with Google + {isAuthenticated === AuthStatus.Authenticating ? ( + + ) : ( + <> + + Continue with Google + + )} )} diff --git a/client/src/pages/auth/index.tsx b/client/src/pages/auth/index.tsx index 8f2dc11..442e7a0 100644 --- a/client/src/pages/auth/index.tsx +++ b/client/src/pages/auth/index.tsx @@ -1,7 +1,6 @@ import { useEffect } from "react"; import { AuthStatus, AuthTab, useAuthStore, useTempStore } from "../../store/useAuthStore"; import { useLocation, useNavigate } from "react-router-dom"; -import { LoadingComponent } from "../../components/loading/svg"; export default function AuthPage() { const location = useLocation(); @@ -13,7 +12,10 @@ export default function AuthPage() { const params = new URLSearchParams(location.search); const type = params.get('type'); - if (isAuthenticated === AuthStatus.Authenticated) { + if (isAuthenticated === AuthStatus.Authenticating) { + setAuthTab(type === 'login' ? AuthTab.Login : type === 'signup' ? AuthTab.Signup : AuthTab.Login); + } + else if (isAuthenticated === AuthStatus.Authenticated) { navigate(route === '/auth' || route === '/login' || route === '/signup' ? '/' : route) } else if (isAuthenticated === AuthStatus.Failed) { @@ -38,5 +40,5 @@ export default function AuthPage() { } }, [isAuthenticated, location.search, navigate, route, setAuthTab, setTempUser]); - return + return
} \ No newline at end of file