Skip to content

Commit

Permalink
client: show auth modal on authenticating
Browse files Browse the repository at this point in the history
  • Loading branch information
Shubham-Lal committed Apr 8, 2024
1 parent 224f274 commit 5080a68
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
4 changes: 2 additions & 2 deletions client/src/components/modal/login-tab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ const LoginTab = () => {
/>
</div>
<button disabled={isAuthenticated === AuthStatus.Authenticating} type='submit'>
{loginData.id && loginData.password && isAuthenticated === AuthStatus.Authenticating ? <LoadingSVG size={23} /> : 'Login'}
{isAuthenticated === AuthStatus.Authenticating ? <LoadingSVG size={23} /> : 'Login'}
</button>
</form>
<div className='or-divider'>
Expand All @@ -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 ? (
<LoadingSVG size={23} />
) : (
<>
Expand Down
13 changes: 10 additions & 3 deletions client/src/components/modal/signup-tab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<RegisterDataProps> = ({ registerData, setRegisterData }) => {
const { setAuthTab, isAuthenticated } = useAuthStore();
Expand Down Expand Up @@ -91,7 +92,7 @@ const SignupTab: React.FC<RegisterDataProps> = ({ registerData, setRegisterData
/>
</div>
<button type='submit'>
Continue
{isAuthenticated === AuthStatus.Authenticating ? <LoadingSVG size={23} /> : 'Continue'}
</button>
</form>
{!tempUser.email && (
Expand All @@ -106,8 +107,14 @@ const SignupTab: React.FC<RegisterDataProps> = ({ registerData, setRegisterData
className='google-btn'
onClick={() => window.location.href = `${import.meta.env.VITE_SERVER_URL}/api/auth/google`}
>
<FcGoogle size={25} />
<span>Continue with Google</span>
{isAuthenticated === AuthStatus.Authenticating ? (
<LoadingSVG size={23} />
) : (
<>
<FcGoogle size={25} />
<span>Continue with Google</span>
</>
)}
</button>
</>
)}
Expand Down
8 changes: 5 additions & 3 deletions client/src/pages/auth/index.tsx
Original file line number Diff line number Diff line change
@@ -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();
Expand All @@ -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) {
Expand All @@ -38,5 +40,5 @@ export default function AuthPage() {
}
}, [isAuthenticated, location.search, navigate, route, setAuthTab, setTempUser]);

return <LoadingComponent />
return <div />
}

0 comments on commit 5080a68

Please sign in to comment.