chore: get the jwt from google
This commit is contained in:
		| @@ -8,6 +8,29 @@ export default function LoginPage() { | ||||
|     const { login } = useAuth(); | ||||
|     const navigate = useNavigate(); | ||||
|  | ||||
|     const handleSuccess = (credentialResponse) => { | ||||
|         try { | ||||
|             const token = credentialResponse.credential; | ||||
|             const decoded = jwtDecode(token); | ||||
|             console.log('Google user decoded:', decoded); | ||||
|  | ||||
|             // save user in context | ||||
|             login({ | ||||
|                 name: decoded.name, | ||||
|                 email: decoded.email, | ||||
|                 picture: decoded.picture, | ||||
|                 token, | ||||
|             }); | ||||
|             console.log('User logged in and saved to context token:', token); | ||||
|         } catch (err) { | ||||
|             console.error('Token decode failed:', err); | ||||
|         } | ||||
|     }; | ||||
|  | ||||
|     const handleError = () => { | ||||
|         console.error('Google login failed'); | ||||
|     }; | ||||
|  | ||||
|     return ( | ||||
|         <Box display="flex" flexDirection="column" alignItems="center" mt={10}> | ||||
|             <Typography variant="h4" gutterBottom> | ||||
| @@ -15,14 +38,8 @@ export default function LoginPage() { | ||||
|             </Typography> | ||||
|  | ||||
|             <GoogleLogin | ||||
|                 onSuccess={(credentialResponse) => { | ||||
|                     const user = jwtDecode(credentialResponse.credential); | ||||
|                     login(user); | ||||
|                     navigate('/'); | ||||
|                 }} | ||||
|                 onError={() => { | ||||
|                     console.log('Error signing in'); | ||||
|                 }} | ||||
|                 onSuccess={handleSuccess} | ||||
|                 onError={handleError} | ||||
|             /> | ||||
|         </Box> | ||||
|     ); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Rodolfo Ruiz
					Rodolfo Ruiz