@@ -4,9 +4,12 @@ import { Card, CardContent } from "@/components/ui/card";
4
4
import GoogleIcon from "@/app/home/components/icon/GoogleIcon" ;
5
5
import { useAuth } from "@/components/auth/AuthContext" ;
6
6
import { useGoogleLogin } from "@react-oauth/google" ;
7
+ import { useRouter } from "next/navigation" ;
8
+ import { useEffect } from "react" ;
7
9
8
10
const LandingPage = ( ) => {
9
- const { login } = useAuth ( ) ;
11
+ const { login, token } = useAuth ( ) ;
12
+ const router = useRouter ( ) ;
10
13
11
14
const googleLogin = useGoogleLogin ( {
12
15
onSuccess : ( response ) => login ( response ) ,
@@ -15,6 +18,20 @@ const LandingPage = () => {
15
18
} ,
16
19
} ) ;
17
20
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
+
18
35
return (
19
36
< div className = "flex items-center justify-center min-h-[90vh]" >
20
37
< div className = "flex items-center justify-between max-w-7xl w-full" >
@@ -26,7 +43,7 @@ const LandingPage = () => {
26
43
Join PeerPrep to sharpen your skills through real-time problem-solving, and prepare to outshine in every interview.
27
44
Created for CS3219 Software Engineering Principles AY24/25 by Group 15.
28
45
</ p >
29
- < Button className = "mt-6 font-semibold w-full" onClick = { ( ) => googleLogin ( ) } >
46
+ < Button className = "mt-6 font-semibold w-full" onClick = { ( ) => handleLogin ( ) } >
30
47
< GoogleIcon />
31
48
< span className = "pl-2" > Get Started with Google</ span >
32
49
</ Button >
0 commit comments