@@ -6,9 +6,8 @@ import { Link } from "react-router-dom";
66import { useAuthModal } from "@/context/AuthModalContext" ;
77import HeaderActions from "./HeaderActions" ;
88import Banner from "./Banner" ;
9- import { CredentialResponse , useGoogleOneTapLogin } from "@react-oauth/google" ;
10- import { postData } from "@/util" ;
119import { useAuth } from "@/context/AuthContext" ;
10+ import GoogleOneTap from "./GoogleOneTap" ;
1211
1312export const NAV_MENU = [
1413 { text : "Home" , link : "/" } ,
@@ -26,37 +25,11 @@ const Header = ({ withBanner = true }: { withBanner?: boolean }) => {
2625 closeForgotPassword,
2726 } = useAuthModal ( ) ;
2827
29- const { login } = useAuth ( ) ;
30-
31- useGoogleOneTapLogin ( {
32- onSuccess : async ( response : CredentialResponse ) => {
33- if ( response . credential ) handleGoogleLogin ( response . credential ) ;
34- } ,
35- onError : async ( ) => {
36- console . log ( "Login Failed" ) ;
37- } ,
38- cancel_on_tap_outside : true ,
39- use_fedcm_for_prompt : true ,
40- } ) ;
41-
42- const handleGoogleLogin = async ( code : string ) => {
43- if ( ! code ) return ;
44-
45- try {
46- const userData = await postData ( "auth/login/google" , { code } , ( ) => { } ) ;
47- if ( userData ) {
48- await login ( userData ) ;
49- }
50- } catch ( err : unknown ) {
51- let errorMessage = "" ;
52- if ( err instanceof Error ) errorMessage = err . message ;
53- // TODO: a toast to show the error: setErrorMessage(`Error sending data to server: ${errorMessage}`);
54- console . log ( `Error sending data to server: ${ errorMessage } ` ) ;
55- }
56- } ;
28+ const { user } = useAuth ( ) ;
5729
5830 return (
5931 < header >
32+ { ! user && < GoogleOneTap /> }
6033 < div className = "bg-background flex items-center py-2" >
6134 < Link
6235 to = "/"
0 commit comments