Skip to content

Commit 1ef77cf

Browse files
committed
custom button for mobile fix
1 parent 61f20d8 commit 1ef77cf

2 files changed

Lines changed: 23 additions & 19 deletions

File tree

frontend/src/App.jsx

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import ProductDetail from './components/ProductDetail'
66
import { ALL_PRODUCTS } from './data/products'
77
import { motion, AnimatePresence } from 'framer-motion'
88
import { X, ShoppingBag, Heart, User, Trash2 } from 'lucide-react'
9-
import { GoogleLogin, googleLogout } from '@react-oauth/google'
9+
import { GoogleLogin, useGoogleLogin } from '@react-oauth/google'
1010
import Checkout from './components/Checkout'
1111
import 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">

frontend/src/index.css

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,9 +1016,8 @@ ul {
10161016
.wishlist-btn-large.wishlisted { background: #fff0e6; color: #e85d04; border-color: #e85d04; }
10171017

10181018
/* Google Login Button */
1019-
.google-btn-wrap { display: flex; justify-content: center; width: 100%; margin-top: 4px; }
1020-
.google-btn-wrap > div { display: flex !important; justify-content: center !important; }
1021-
.google-btn-wrap iframe { margin: 0 auto !important; }
1019+
.google-custom-btn { display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%; padding: 12px; border: 1.5px solid #e0e0e0; border-radius: 10px; background: #fff; font-size: 14px; font-weight: 600; color: #333; cursor: pointer; margin-top: 4px; }
1020+
.google-custom-btn:hover { background: #f5f5f5; border-color: #ccc; }
10221021

10231022
/* User Profile in Header */
10241023
.user-profile-wrap { position: relative; }

0 commit comments

Comments
 (0)