From 5d0e3af1ac0230552b968800f03a24f00bf58c20 Mon Sep 17 00:00:00 2001 From: Jerome Hardaway Date: Sat, 23 Nov 2024 21:49:14 -0500 Subject: [PATCH] add login updates --- src/pages/login.tsx | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/pages/login.tsx b/src/pages/login.tsx index 0498d97e..04d9f81b 100644 --- a/src/pages/login.tsx +++ b/src/pages/login.tsx @@ -25,13 +25,15 @@ const Login: PageWithLayout = () => { const [error, setError] = useState(null); const [isRedirecting, setIsRedirecting] = useState(false); - // Handle authenticated state - useEffect(() => { + // Handle authenticated state with proper return type + useEffect((): (() => void) => { + const cleanup = (): void => { + // Cleanup function + }; + if (status === "authenticated" && !isRedirecting) { setIsRedirecting(true); - - // Set a timeout for the redirect - const redirectTimeout = setTimeout(() => { + const timeout = setTimeout(() => { router.push("/profile").catch((err) => { setError("Failed to redirect to profile. Please try refreshing the page."); setIsRedirecting(false); @@ -41,8 +43,12 @@ const Login: PageWithLayout = () => { }); }, 100); - return () => clearTimeout(redirectTimeout); + return () => { + clearTimeout(timeout); + }; } + + return cleanup; }, [status, router, isRedirecting]); const handleSignIn = useCallback(async () => { @@ -53,7 +59,6 @@ const Login: PageWithLayout = () => { redirect: true, }); - // Handle failed sign-in if (result?.error) { setError("Failed to sign in with GitHub. Please try again."); if (process.env.NODE_ENV === "development") { @@ -68,7 +73,6 @@ const Login: PageWithLayout = () => { } }, []); - // Show loading state if (!mounted || status === "loading") { return (
@@ -77,7 +81,6 @@ const Login: PageWithLayout = () => { ); } - // Show login form for unauthenticated users if (status === "unauthenticated") { return (
@@ -130,7 +133,6 @@ const Login: PageWithLayout = () => { ); } - // Show redirect state return (