Authentication
Google Login
Single Sign-On using Google OAuth with automatic account linking.
Google Login
In addition to traditional email and password credentials, GO Shortener supports Single Sign-On (SSO) via Google, allowing users to sign in or register with a single click.
Authentication Flow
+----------+ +------------+ +-----------------+
| Browser | ------------ | Firebase | ------------ | Google OAuth |
+----------+ +------------+ +-----------------+
| | |
| 1. Click "Sign in" | |
|------------------------> | |
| | 2. Perform OAuth Consent |
| |----------------------------> |
| | 3. ID Token Returned |
| |<---------------------------- |
| 4. Receive Firebase JWT | |
|<-------------------------| |
| |
| 5. POST /api/auth/google { idToken } |
|-------------------------------------------------------->|
| |
| 6. Validate Token & Issue `go_session` Cookie |
|<--------------------------------------------------------|
- Client-Side Trigger: The user clicks Continue with Google on the login or registration modal.
- Google OAuth Popup: Firebase Web SDK manages the OAuth popup flow and Google account consent.
- ID Token Generation: Upon authorization, Firebase issues a signed OpenID Connect (OIDC) JWT to the browser.
- Backend Verification: The browser submits the JWT to
POST /api/auth/google. The GO backend cryptographically verifies the token's signature, issuer, and audience against Google's public certificates. - Session Established: The backend issues the standard
go_sessioncookie, seamlessly authenticating the user.
Automatic Account Linking
A key design feature in GO Shortener is Safe Account Linking:
If a user initially registered an account using an email and password (e.g.,
alice@example.com) and subsequently clicks Continue with Google with that same Google account, GO links the credentials automatically rather than failing or creating a duplicate user row.Linking Logic:
- The backend extracts the verified email address and Firebase UID from the validated Google token.
- It queries the
userstable for an existing record matching that email address. - If found:
- Sets
firebase_uid = token.UID - Sets
auth_provider = "google"(or hybrid) - Updates
last_login_at = CURRENT_TIMESTAMP
- Sets
- If not found:
- Creates a new user row with
email,first_name,last_name, andauth_provider = "google". - The user immediately inherits the normal registered user quota (100 links/month).
- Creates a new user row with