How the flow works
Initiate the login
Direct the user’s browser to
GET /api/auth/google. The server redirects to Google’s OAuth consent page, requesting access to the user’s profile and email scopes.User grants consent
The user logs in to their Google account and approves the requested permissions.
Google redirects back
Google redirects the browser to
GET /api/auth/google/callback with an authorization code. The server exchanges the code for user profile data using Passport.js.Tokens issued
The server creates a device session, generates a JWT access token and a refresh token, and sets the Read the token from
refreshToken httpOnly cookie. The browser is then redirected to the frontend callback URL with the access token in the URL fragment:window.location.hash and store it securely in memory.Endpoints
Initiate Google login
OAuth callback
Error handling
| Error query parameter | Cause |
|---|---|
google_auth_failed | Google returned an error, the OAuth flow failed, or the user object was invalid |
After successful OAuth
Once the user completes the flow:- A new device session is created and stored.
- A refresh token (7-day expiry) is set as an
httpOnlycookie. - An access token is passed in the URL fragment to the frontend callback page.
- Subsequent API requests work identically to password-based login — use the access token in the
Authorization: Bearerheader and refresh it viaPOST /api/auth/refreshwhen it expires.
If the Google account email matches an existing Hayon account, the user is authenticated into that account. If no account exists, a new one is created automatically.
