Skip to content

Commit 24d6cac

Browse files
committed
Fix conditional rendering bug
1 parent 34eb9df commit 24d6cac

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed
Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,26 @@
11
"use client";
22

33
import { useAuth } from "@/components/auth/AuthContext";
4+
import { useState, useEffect } from "react";
45
import LandingPage from "@/app/(home)/components/landing-page/LandingPage";
56
import LeetcodeDashboard from "./LeetcodeDashboard";
67

78
const Home = () => {
89
const { token } = useAuth();
10+
const [loading, setLoading] = useState(true);
911

10-
return (
11-
token ? <LeetcodeDashboard/> : <LandingPage/>
12-
);
12+
// Simulate token fetching or resolving logic
13+
useEffect(() => {
14+
if (token !== undefined) {
15+
setLoading(false);
16+
}
17+
}, [token]);
18+
19+
if (loading) {
20+
return null;
21+
}
22+
23+
return token ? <LeetcodeDashboard /> : <LandingPage />;
1324
};
1425

15-
export default Home;
26+
export default Home;

frontend/src/app/(home)/components/landing-page/LandingPage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const LandingPage = () => {
1313
const googleLogin = useGoogleLogin({
1414
onSuccess: (response) => {
1515
login(response);
16-
//router.push("/leetcode-dashboard"); // Redirect to dashboard after successful login
16+
router.push("/leetcode-dashboard"); // Redirect to dashboard after successful login
1717
},
1818
onError: (error) => {
1919
console.error("Login Failed:", error);

0 commit comments

Comments
 (0)