Authentication Flow
Current Main Production Flow
HashPass main production (https://hashpass.tech) Google sign-in uses the API-owned OAuth bridge. The browser no longer relies on Directus session cookies from sso.hashpass.co to complete login.
- The frontend calls
GET /api/auth/oauth/login?provider=google&returnTo=.... - The API stores
oauth_return_to,oauth_frontend_origin, andoauth_google_statecookies. - The API redirects the browser to Google with:
redirect_uri=https://api.hashpass.tech/api/auth/oauth/googlescope=openid profile email
- Google sends the authorization
codeback toGET /api/auth/oauth/google. - The API exchanges the code with Google, loads the Google profile, and logs into Directus as the configured admin user.
- The API creates or updates the Directus user record, normalizes it to a local provider, and gets Directus tokens for that user.
- The API redirects back to the requested frontend path with
#access_token=...&refresh_token=.... - The frontend auth layer reads the hash fragment and establishes the active session.
Why This Exists
This bridge avoids the production cookie problem between:
- Frontend:
https://hashpass.tech - Directus:
https://sso.hashpass.co
Cross-site Directus cookies were not reliable enough for the production browser flow, so the OAuth callback now runs through the API domain instead.
Production Requirements
GOOGLE_CLIENT_IDGOOGLE_CLIENT_SECRETADMIN_EMAILADMIN_PASSWORDDEFAULT_ROLE_IDDIRECTUS_URLEXPO_PUBLIC_FRONTEND_URL
The Directus admin account used by the API callback must be a local Directus user (provider=default) and remain active.
Relevant Routes
apps/mobile-app/app/api/auth/[...auth]+api.tsapps/mobile-app/app/api/auth/oauth/login+api.tsapps/mobile-app/app/api/auth/oauth/google+api.tsapps/mobile-app/app/api/auth/oauth/callback+api.tsapps/mobile-app/app/(shared)/auth/callback.tsx
Event Better Auth Flow
Event tenants (https://bsl.hashpass.tech and https://bsl-dev.hashpass.tech) use Better Auth for Google social login. Main hashpass.tech remains on Directus.
- Domain-aware auth selection resolves event tenants to
better-auth. - The frontend calls Better Auth at
EXPO_PUBLIC_BETTER_AUTH_URL, normallyhttps://api.hashpass.tech/api/authin production, while the browser runtime exposes public Supabase values throughwindow.__HASHPASS_RUNTIME__for client-side helpers. - Better Auth handles Google OAuth at
/api/auth/*, stores its session in secure cookies, and redirects back to/auth/callback. - The shared auth callback asks the active provider for the session, then routes the user to the requested event path.
- Event API calls include credentials, and server-side
authenticateRequest()validates the Better Auth cookie for event hosts.
Event production requirements:
BETTER_AUTH_SECRETBETTER_AUTH_URL=https://api.hashpass.tech/api/authEXPO_PUBLIC_BETTER_AUTH_URL=https://api.hashpass.tech/api/authBETTER_AUTH_DATABASE_URLorBSL_BETTER_AUTH_DATABASE_URLBETTER_AUTH_GOOGLE_CLIENT_ID/BETTER_AUTH_GOOGLE_CLIENT_SECRET(or the existingGOOGLE_CLIENT_ID/GOOGLE_CLIENT_SECRET)- Google OAuth redirect URI:
https://api.hashpass.tech/api/auth/callback/google
When you sync production or development secrets, packages/tools/scripts/util/setup-parameters.sh sync keeps the BSL Better Auth subtree under /hashpass/[env]/bsl/better-auth/ and preserves the public Supabase key aliases used by the browser runtime.
Run the Better Auth schema migration against the configured event database after changing Better Auth config:
pnpm exec @better-auth/cli migrate --config apps/mobile-app/lib/server/better-auth.ts
Troubleshooting
- If login fails before Google opens, check the API route response from
/api/auth/oauth/login. - If Google returns an error, check the
statecookie and the Google redirect URI registered in Google Cloud Console. - If the API callback fails with
Failed to authenticate as admin, verify the Directus admin row is local and the password matches the production env. - If the browser lands on
/dashboard/explore?error=oauth_failed..., check the API Lambda logs for the callback request ID. - For Better Auth failures, check
/api/auth/ok,/api/auth/get-session, Google redirect URI configuration, and whether cookies are being sent toapi.hashpass.tech.