POST
Sign in with Google

Overview

Signs a user in (or registers them on first use) with their Google account. The mobile app performs native Google sign-in via the Firebase Auth SDK, obtains a Firebase ID token, and POSTs that token here. The backend verifies the token with firebase-admin — checking the signature against Google’s rotating public keys, the expiry, the issuer, and that the token’s audience matches our Firebase project — then returns a Swappr access + refresh token pair, exactly like /login. There are three outcomes:
  • First-time Google user → a new account is created (emailVerified mirrors the token’s email_verified claim, firstName / lastName start null, consent flags start false). The response is 201 Created with isNewUser: true. The client should route the user into onboarding.
  • Returning Google user (same Google identity) → 200 OK with isNewUser: false.
  • Email already owned by a non-Google account → 409 ACCOUNT_EXISTS_VIA_OAUTH. Swappr does not silently attach Google to a pre-existing email/password (or Apple) account — that would allow account takeover by anyone able to mint a Google token for that address. The user must sign in with their original method and link Google deliberately from settings (account linking is future work).
New Google users flow into the same onboarding state machine as email users; use isNewUser (or onboardingStep) to decide whether to show onboarding.

Authentication

None required. The Firebase ID token in the body is the credential.

Path parameters

None.

Query parameters

None.

Request body

Example payload

Response — 201 Created (new user) / 200 OK (returning user)

Example response — 201

Error responses

Example error — 401

Side effects

  • First-time sign-in only: inserts a new row into the users collection with oauthProvider: 'GOOGLE', oauthId set to the Firebase uid, passwordHash: null, and emailVerified taken from the token.
  • Issues a new session: inserts a refresh_tokens row and signs an access JWT.
  • No email is sent (no OTP needed — Google has already verified the address).

Rate limiting

This endpoint shares the auth burst limiter (10 requests / minute / IP) with /login, on top of the router-level /auth/* cap.

Notes for the client

  1. Configure Firebase in the app with the bundled google-services.json (Android) / GoogleService-Info.plist (iOS) for project swappr-de6ce, bundle id com.swappr.app.
  2. Do native Google sign-in (Firebase Auth GoogleAuthProvider), then read the ID token (user.getIdToken()), not the access token.
  3. POST { idToken } here, store the returned Swappr accessToken / refreshToken, and proceed exactly as with email login.

See also

curl