@@ -6,7 +6,7 @@ import ProductDetail from './components/ProductDetail'
66import { ALL_PRODUCTS } from './data/products'
77import { motion , AnimatePresence } from 'framer-motion'
88import { X , ShoppingBag , Heart , User , Trash2 } from 'lucide-react'
9- import { GoogleLogin , googleLogout } from '@react-oauth/google'
9+ import { GoogleLogin , useGoogleLogin } from '@react-oauth/google'
1010import Checkout from './components/Checkout'
1111import AccountModal from './components/AccountModal'
1212
@@ -248,6 +248,22 @@ const Overlay = ({ type, onClose, cartItems, wishlistItems, onRemoveFromCart, on
248248 const isDrawer = type === 'cart' || type === 'wishlist' ;
249249 const cartTotal = cartItems . reduce ( ( sum , i ) => sum + i . price * i . qty , 0 ) ;
250250
251+ const googleLogin = useGoogleLogin ( {
252+ onSuccess : async ( tokenResponse ) => {
253+ try {
254+ const res = await fetch ( 'https://www.googleapis.com/oauth2/v3/userinfo' , {
255+ headers : { Authorization : `Bearer ${ tokenResponse . access_token } ` }
256+ } ) ;
257+ const data = await res . json ( ) ;
258+ onLoginSuccess ( { name : data . name , email : data . email , picture : data . picture } ) ;
259+ onClose ( ) ;
260+ } catch ( e ) {
261+ console . log ( 'Google login failed' , e ) ;
262+ }
263+ } ,
264+ onError : ( ) => console . log ( 'Google login failed' ) ,
265+ } ) ;
266+
251267 const handleAuth = ( ) => {
252268 setError ( '' ) ;
253269 if ( ! formData . email || ! formData . password ) { setError ( 'Please fill all fields' ) ; return ; }
@@ -376,21 +392,10 @@ const Overlay = ({ type, onClose, cartItems, wishlistItems, onRemoveFromCart, on
376392 { error && < p className = "auth-error" > { error } </ p > }
377393 < button className = "btn-primary auth-btn" onClick = { handleAuth } > { isSignUp ? 'CREATE ACCOUNT' : 'SIGN IN' } </ button >
378394 < div className = "separator" > < span > OR CONTINUE WITH</ span > </ div >
379- < div className = "google-btn-wrap" >
380- < GoogleLogin
381- onSuccess = { ( credentialResponse ) => {
382- const base64 = credentialResponse . credential . split ( '.' ) [ 1 ] ;
383- const decoded = JSON . parse ( atob ( base64 ) ) ;
384- onLoginSuccess ( decoded ) ;
385- onClose ( ) ;
386- } }
387- onError = { ( ) => console . log ( 'Google login failed' ) }
388- width = "360"
389- text = { isSignUp ? 'signup_with' : 'signin_with' }
390- shape = "rectangular"
391- size = "large"
392- />
393- </ div >
395+ < button className = "google-custom-btn" onClick = { ( ) => googleLogin ( ) } >
396+ < img src = "https://www.gstatic.com/firebasejs/ui/2.0.0/images/auth/google.svg" alt = "Google" width = "20" height = "20" />
397+ { isSignUp ? 'Sign up with Google' : 'Sign in with Google' }
398+ </ button >
394399 </ div >
395400
396401 < p className = "auth-footer" >
0 commit comments