Skip to main content

Endpoint

POST /api/auth/google
Authenticate users using Google OAuth via Firebase. This endpoint accepts a Firebase ID token and creates or logs in a user account.
This endpoint is rate limited to 5 requests per 15 minutes in production.

Request Body

idToken
string
required
Firebase ID token obtained from Google Sign-In on the client side

Response

accessToken
string
JWT access token valid for 15 minutes
refreshToken
string
JWT refresh token valid for 7 days
user
object
User information

Example Request

cURL
curl -X POST https://api.contafy.com/api/auth/google \
  -H "Content-Type: application/json" \
  -d '{
    "idToken": "eyJhbGciOiJSUzI1NiIsImtpZCI6..."
  }'

Success Response

{
  "accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
  "refreshToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
  "user": {
    "id": "123e4567-e89b-12d3-a456-426614174000",
    "email": "[email protected]",
    "nombre": "Juan",
    "apellido": "Pérez",
    "email_verified": true,
    "logo_url": "https://lh3.googleusercontent.com/a/..."
  }
}

Error Responses

400 Bad Request

{
  "error": "Error de validación",
  "details": [
    {
      "field": "idToken",
      "message": "El idToken de Firebase es obligatorio"
    }
  ]
}

401 Unauthorized

{
  "error": "Token de Firebase inválido",
  "message": "No se pudo verificar el token de Firebase"
}

429 Too Many Requests

{
  "error": "Demasiados intentos de autenticación, por favor intenta nuevamente más tarde."
}

500 Internal Server Error

{
  "error": "Error interno del servidor",
  "message": "Error al procesar la autenticación con Google"
}

How It Works

  1. User signs in with Google on the client side using Firebase Authentication
  2. Client receives a Firebase ID token
  3. Client sends the ID token to this endpoint
  4. Server verifies the token with Firebase
  5. Server creates a new user account (if first login) or retrieves existing user
  6. Server automatically verifies the email (Google accounts are pre-verified)
  7. Server creates a FREE subscription for new users
  8. Server returns JWT tokens for API access
Google OAuth users have their email automatically verified and do not need to go through the email verification flow.
  • Login - Standard email/password authentication
  • Register - Create account with email/password
  • Get Current User - Retrieve authenticated user information

Build docs developers (and LLMs) love