Skip to content

Commit 4d1a89e

Browse files
committed
Fix routing to dashboard after authentication
1 parent b249658 commit 4d1a89e

File tree

3 files changed

+27
-21
lines changed

3 files changed

+27
-21
lines changed

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

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@ import { Card, CardContent } from "@/components/ui/card";
44
import GoogleIcon from "@/app/home/components/icon/GoogleIcon";
55
import { useAuth } from "@/components/auth/AuthContext";
66
import { useGoogleLogin } from "@react-oauth/google";
7+
import { useRouter } from "next/navigation";
8+
import { useEffect } from "react";
79

810
const LandingPage = () => {
9-
const { login } = useAuth();
11+
const { login, token } = useAuth();
12+
const router = useRouter();
1013

1114
const googleLogin = useGoogleLogin({
1215
onSuccess: (response) => login(response),
@@ -15,6 +18,20 @@ const LandingPage = () => {
1518
},
1619
});
1720

21+
useEffect(() => {
22+
if (token) {
23+
router.push("/");
24+
}
25+
}, [token, router]);
26+
27+
const handleLogin = () => {
28+
if (token) {
29+
router.push("/");
30+
} else {
31+
googleLogin();
32+
}
33+
}
34+
1835
return (
1936
<div className="flex items-center justify-center min-h-[90vh]">
2037
<div className="flex items-center justify-between max-w-7xl w-full">
@@ -26,7 +43,7 @@ const LandingPage = () => {
2643
Join PeerPrep to sharpen your skills through real-time problem-solving, and prepare to outshine in every interview.
2744
Created for CS3219 Software Engineering Principles AY24/25 by Group 15.
2845
</p>
29-
<Button className="mt-6 font-semibold w-full" onClick={() => googleLogin()}>
46+
<Button className="mt-6 font-semibold w-full" onClick={() => handleLogin()}>
3047
<GoogleIcon/>
3148
<span className="pl-2">Get Started with Google</span>
3249
</Button>

frontend/src/app/home/page.tsx

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

3-
import Homepage from "@/app/home/unauthenticated-homepage/homepage";
3+
import Navbar from "@/app/home/components/navbar/Navbar";
4+
import LandingPage from "@/app/home/components/landing-page/LandingPage";
45

56
const Home = () => {
6-
return (
7-
<Homepage />
8-
);
7+
return (
8+
<>
9+
<Navbar />
10+
<LandingPage />
11+
</>
12+
);
913
};
1014

1115
export default Home;

frontend/src/app/home/unauthenticated-homepage/homepage.tsx

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)