Repository navigation
feat(auth): switch NextAuth SSO from AWS Cognito to Google OAuth - #61
Conversation
Replaces the Cognito provider with next-auth's Google provider and updates the login/register buttons, e2e SSO flow, and marketing copy to match. - auth-options: GoogleProvider, gated on GOOGLE_CLIENT_ID - env: declare GOOGLE_CLIENT_ID/SECRET and OLLAMA_BASE_URL (web-ui + shared); keep Cognito vars as optional legacy - .env.example: document Google OAuth and the Ollama provider - .gitignore: ignore .env.bak.* backups Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
kartikmanimuthu
left a comment
There was a problem hiding this comment.
Thanks @Thirunavukkarasu — the mechanical part of this is complete and careful: provider, both T3 env schemas, login/register buttons, marketing copy, .env.example and the e2e page object all move together, and leaving the Cognito vars declared so libs/shared exports keep working was the right call. No secrets committed either. Note that the red CI on this PR is not yours — the failing step is env validation (Invalid environment variables in libs/claw-studio/src/env.ts and apps/workers/src/env.ts), the same failure main has had since early September. #62 fixes that.
Three things I'd like to settle before this ships, because it changes how every user signs in:
- The migration is half-done.
libs/shared/src/services/invitation-service.tsstill sends Cognito invitations, andcognito-client.tsis still exported. After this lands, an invited user receives a link to a Cognito hosted UI that can no longer authenticate anyone. Either finish the invitation path here or gate invitations off in the same release — otherwise invites become a dead end. - Validate the Google pair together. The provider is gated on
GOOGLE_CLIENT_IDalone, andclientSecret: env.GOOGLE_CLIENT_SECRET!is a non-null assertion. Set the ID and forget the secret and you get a provider with anundefinedsecret and a 500 at token exchange. A Zod.refinefor both-or-neither turns that into a startup error. - The e2e SSO flow can't work as written (
sso.flow.ts:18-20): it still fills Cognito'sname@host.com/Passwordfields, and Google blocks automated sign-in outright ("This browser or app may not be secure"). The repo already mints real NextAuth sessions insetup/auth.setup.ts, so a seededstorageStatesession would be both simpler and stable.
Worth a deliberate decision, not a blocker: allowDangerousEmailAccountLinking: true. Google verifies e-mails, so it's far safer than with an arbitrary OIDC issuer — but it silently links an existing password account to a Google identity claiming that e-mail, and it routes around the lockout logic directly above it (a locked-out account can just sign in with Google). If that's intended, a note in the PR and a signIn callback that refuses linking when user.passwordHash exists would make it explicit.
Minor: the .catch(() => { }) and constructor(private readonly page: Page) { } reformatting — Prettier's output for an empty body is {}, so prettier --check would put those back. Dropping them keeps the diff about auth. Also auth-options.ts:48 still says "sign in with the SSO tab" while the button now reads "Sign in with Google".
Approving — thanks, and thanks for verifying the real consent screen end-to-end rather than trusting the config.
Summary
Replaces the AWS Cognito identity provider in NextAuth with Google OAuth, so tenants sign in with Google instead of a Cognito-hosted UI.
What changed
libs/shared/src/auth/auth-options.ts— swapsCognitoProviderfornext-auth'sGoogleProvider, gated onGOOGLE_CLIENT_ID. Credentials login is untouched.apps/web-ui/lib/env.ts,libs/shared/src/env.ts— declareGOOGLE_CLIENT_ID/GOOGLE_CLIENT_SECRET, andOLLAMA_BASE_URL. Cognito vars are kept as optional legacy so nothing else that reads them breaks.apps/web-ui/app/(auth)/login/page.tsx,register/page.tsx— buttons now callsignIn('google')and read "Sign in / Sign up with Google".apps/web-ui-e2e/src/pages/sso.flow.ts— e2e SSO flow targets the Google button and no longer assumes Cognito's hosted UI.apps/web-ui/app/(marketing)/components/feature-grid.tsx— marketing copy updated from Cognito to Google..env.example— documents Google OAuth (redirect URIhttp://localhost:3005/api/auth/callback/google) and the Ollama provider..gitignore— ignores local.env.bak.*backups.Notes for reviewers
.envand its backups are gitignored;.env.examplecarries placeholders only.OLLAMA_BASE_URLis the only Ollama env var this app reads (used bylibs/knowledge-basefor local embeddings/reranking). Ollama chat providers and credentials are configured per-tenant in the UI (LlmProvidertable), not from env.libs/sharedstill exports Cognito helpers (cognito-client.ts,invitation-service.ts) used elsewhere.Testing
nx run-many -t typecheck -p shared,web-ui— ✅ passed.http://localhost:3005/api/auth/callback/googleto the OAuth client's authorized redirect URIs).Follow-ups (not in this PR)
libs/shared/src/services/invitation-service.tsstill uses Cognito for invitation emails.