curl --request GET \
--url https://api.example.com/api/auth/google{
"sub": "<string>",
"email": "<string>",
"role": "<string>",
"iat": 123
}Authenticate users with Google OAuth 2.0
curl --request GET \
--url https://api.example.com/api/auth/google{
"sub": "<string>",
"email": "<string>",
"role": "<string>",
"iat": 123
}curl -X GET https://api.yourfinanceapp.com/api/auth/google
https://accounts.google.com/o/oauth2/v2/auth?client_id=...&redirect_uri=...&scope=email+profile
{FRONTEND_URL}/oauth/callback?token={jwt_token}
https://yourapp.com/oauth/callback?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
{FRONTEND_URL}/login?error=auth_failed
https://yourapp.com/login?error=auth_failed
GOOGLEARSUSERnull (OAuth users don’t have passwords)GOOGLE (if previously LOCAL)authProviderId// Redirect user to initiate OAuth flow
const handleGoogleLogin = () => {
window.location.href = 'https://api.yourfinanceapp.com/api/auth/google';
};
// Extract token from URL after redirect
const url = new URL(window.location.href);
const token = url.searchParams.get('token');
const error = url.searchParams.get('error');
if (token) {
// Store token and redirect to dashboard
localStorage.setItem('authToken', token);
window.location.href = '/dashboard';
} else if (error === 'auth_failed') {
// Handle authentication failure
console.error('Google authentication failed');
}
GOOGLE_CLIENT_ID - OAuth 2.0 client ID from Google Cloud ConsoleGOOGLE_CLIENT_SECRET - OAuth 2.0 client secretGOOGLE_CALLBACK_URL - Authorized redirect URI (e.g., https://api.yourfinanceapp.com/api/auth/google/callback)FRONTEND_URL - Your frontend application URL for post-auth redirectsFRONTEND_URL configuration results in 500 error to prevent misconfiguration in production