Overview
FitAiid supports Google OAuth for both login and registration. These are separate endpoints with distinct purposes:- Google Login: For users who already have a FitAiid account
- Google Register: For new users creating an account with Google
Both endpoints require Firebase Authentication on the client side. Users must first authenticate with Firebase, then send the Firebase UID to the backend.
Google Login
Authenticate an existing user with their Google account
Authentication
Not required - public endpoint
Request Body
User’s Google email address
- Must already be registered in FitAiid database
- Will be converted to lowercase
- Example: “[email protected]”
Firebase Authentication UID
- Obtained from Firebase after Google authentication
- Used to verify the user’s identity
User’s first name from Google profile (optional, for logging purposes)
User’s last name from Google profile (optional, for logging purposes)
Response
Indicates if login was successful
Success message: “Inicio de sesión con Google exitoso”
JWT authentication token (expires in 30 days by default)
Complete user profile (same structure as standard login)
Error Responses
| Status Code | Error Message | Description |
|---|---|---|
| 400 | ”El email y UID son obligatorios” | Missing email or uid in request |
| 401 | ”Tu cuenta ha sido desactivada. Contacta soporte.” | Account is inactive |
| 404 | ”Este correo no está registrado. Por favor regístrate primero.” | Email not found in database |
Code Examples
Example Response
Google Register
Create a new user account using Google OAuth
Authentication
Not required - public endpoint
Request Body
User’s Google email address
- Must NOT already exist in FitAiid database
- Will be converted to lowercase
- Example: “[email protected]”
Firebase Authentication UID
- Obtained from Firebase after Google authentication
- Verified with Firebase Admin SDK on backend
User’s first name
- If not provided, extracted from Firebase displayName
- Falls back to “Usuario” if unavailable
User’s last name
- If not provided, extracted from Firebase displayName
- Falls back to “Google” if unavailable
Response
Indicates if registration was successful
Success message: “Registro con Google exitoso”
JWT authentication token (expires in 30 days by default)
Newly created user profile
Error Responses
| Status Code | Error Message | Description |
|---|---|---|
| 400 | ”El email y UID son obligatorios” | Missing email or uid in request |
| 400 | ”Este correo ya está registrado. Por favor inicia sesión.” | Email already exists in database |
| 400 | ”Error al verificar con Google. Intenta de nuevo.” | Firebase UID verification failed |
Code Examples
Example Response
Implementation Flow
Client Authentication
User clicks “Sign in with Google” button and authenticates with Firebase on the client side.
Choose Endpoint
- If registering new user: call
/api/auth/google-register - If logging in existing user: call
/api/auth/google
Backend Verification
For registration, backend verifies the UID with Firebase Admin SDK to ensure authenticity.
Security Features
Firebase Verification
For registration, the backend verifies the Firebase UID with Firebase Admin SDK to prevent fraudulent account creation.
Email Verification
Google OAuth users are automatically marked as email verified since Google has already verified their email.
Temporary Password
Google users are assigned the temporary password “GoogleTemp123” (securely hashed). They should never need to use it.
Activity Logging
All Google authentication events are logged with IP address for security auditing.
Common Issues
Error: Este correo ya está registrado
Error: Este correo ya está registrado
The email is already in the database. Use
/api/auth/google for login instead of /api/auth/google-register.Error: Este correo no está registrado
Error: Este correo no está registrado
The email doesn’t exist in the database. Use
/api/auth/google-register to create an account first.Error: Error al verificar con Google
Error: Error al verificar con Google
The Firebase UID is invalid or expired. Ensure the user properly authenticated with Firebase first and the UID is current.
Next Steps
Get Profile
Retrieve user profile after authentication
Email Registration
Alternative registration with email/password