@@ -7,6 +7,7 @@ import { ALL_PRODUCTS } from './data/products'
77import { motion , AnimatePresence } from 'framer-motion'
88import { X , ShoppingBag , Heart , User , Trash2 } from 'lucide-react'
99import { GoogleLogin } from '@react-oauth/google'
10+ import { jwtDecode } from 'jwt-decode'
1011
1112function App ( ) {
1213 const [ selectedCategories , setSelectedCategories ] = useState ( [ ] ) ;
@@ -18,6 +19,7 @@ function App() {
1819 const [ sortOption , setSortOption ] = useState ( 'recommended' ) ;
1920 const [ activeNav , setActiveNav ] = useState ( 'MEN' ) ;
2021 const [ sneakersView , setSneakersView ] = useState ( false ) ;
22+ const [ loggedInUser , setLoggedInUser ] = useState ( null ) ;
2123
2224 const toggleFilter = ( item , type ) => {
2325 if ( type === 'category' ) {
@@ -90,6 +92,8 @@ function App() {
9092 cartCount = { cartItems . reduce ( ( sum , i ) => sum + i . qty , 0 ) }
9193 wishlistCount = { wishlistItems . length }
9294 activeNav = { activeNav }
95+ loggedInUser = { loggedInUser }
96+ onLogout = { ( ) => setLoggedInUser ( null ) }
9397 />
9498
9599 < main className = "app-main" >
@@ -159,14 +163,15 @@ function App() {
159163 wishlistItems = { wishlistItems }
160164 onRemoveFromCart = { removeFromCart }
161165 onToggleWishlist = { toggleWishlist }
166+ onLoginSuccess = { setLoggedInUser }
162167 />
163168 ) }
164169 </ AnimatePresence >
165170 </ div >
166171 )
167172}
168173
169- const Overlay = ( { type, onClose, cartItems, wishlistItems, onRemoveFromCart, onToggleWishlist } ) => {
174+ const Overlay = ( { type, onClose, cartItems, wishlistItems, onRemoveFromCart, onToggleWishlist, onLoginSuccess } ) => {
170175 const [ isSignUp , setIsSignUp ] = useState ( false ) ;
171176 const isDrawer = type === 'cart' || type === 'wishlist' ;
172177 const cartTotal = cartItems . reduce ( ( sum , i ) => sum + i . price * i . qty , 0 ) ;
@@ -276,7 +281,8 @@ const Overlay = ({ type, onClose, cartItems, wishlistItems, onRemoveFromCart, on
276281 < div className = "google-btn-wrap" >
277282 < GoogleLogin
278283 onSuccess = { ( credentialResponse ) => {
279- console . log ( 'Google login success' , credentialResponse ) ;
284+ const decoded = jwtDecode ( credentialResponse . credential ) ;
285+ onLoginSuccess ( decoded ) ;
280286 onClose ( ) ;
281287 } }
282288 onError = { ( ) => console . log ( 'Google login failed' ) }
0 commit comments