feat(web): replace local OTP auth with @opengovsg/auth - #681
Open
karrui wants to merge 6 commits into
Open
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
karrui
force-pushed
the
karrui/use-opengovsg-auth
branch
from
August 11, 2026 09:48
b8d8286 to
199412c
Compare
|
🎯 Code Coverage (details) 🔗 Commit SHA: eacdea4 | Docs | Datadog PR Page | Give us feedback! |
Contributor
There was a problem hiding this comment.
Warning
- Copilot's review of this pull request may be incomplete because some of the changed files are excluded by your Copilot content exclusion settings. See Excluding content from Copilot for details.
Pull request overview
This PR migrates the web app’s OTP + PKCE sign-in flow from an in-repo implementation to @opengovsg/auth, wiring issuance/verification through createOtpAuth and removing the now-redundant local auth/PKCE utilities.
Changes:
- Added
@opengovsg/authdependency and updated validators to use package-provided OTP defaults + code-challenge validation. - Reworked server auth flow to issue/verify OTPs via
createOtpAuthbacked by a PrismaVerificationTokenStoreadapter. - Deleted local OTP hashing utilities and PKCE helpers; updated sign-in wizard + tests to use
@opengovsg/auth/pkce.
Reviewed changes
Copilot reviewed 11 out of 13 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| pnpm-lock.yaml | Adds @opengovsg/auth snapshot and updates lock entries accordingly. |
| apps/web/package.json | Adds @opengovsg/auth and removes direct nanoid dependency. |
| apps/web/src/validators/auth.ts | Switches OTP/PKCE constants + code-challenge validation to @opengovsg/auth. |
| apps/web/src/validators/tests/auth.spec.ts | Updates PKCE test to use @opengovsg/auth/pkce (now async). |
| apps/web/src/server/modules/auth/auth.service.ts | Replaces custom OTP issuance/verification logic with createOtpAuth and error mapping. |
| apps/web/src/server/modules/auth/verification-token.store.ts | Prisma-backed token store adapter for @opengovsg/auth (content excluded from review). |
| apps/web/src/server/modules/auth/tests/auth.service.spec.ts | Refactors auth service tests to validate the new issue/verify behavior via email-parsed OTP. |
| apps/web/src/server/modules/auth/auth.utils.ts | Removes in-repo OTP/token hashing + identifier helpers. |
| apps/web/src/server/modules/auth/tests/auth.utils.spec.ts | Removes tests for deleted auth.utils helpers. |
| apps/web/src/lib/pkce/server-pkce.ts | Removes server PKCE helper in favor of package implementation. |
| apps/web/src/lib/pkce/constants.ts | Removes PKCE constants/generator in favor of package implementation. |
| apps/web/src/lib/pkce/browser-pkce.ts | Removes browser PKCE helper in favor of package implementation. |
| apps/web/src/app/(public)/sign-in/_components/wizard/context.tsx | Switches client-side PKCE generation to @opengovsg/auth/pkce. |
Files not reviewed (1)
- pnpm-lock.yaml: Generated file
Files excluded by content exclusion policy (1)
- apps/web/src/server/modules/auth/verification-token.store.ts
Suppressed comments (1)
apps/web/src/server/modules/auth/auth.service.ts:96
codeVerifieris a PKCE secret and should not be written to logs. Logging it astokenIdmakes it retrievable from log storage and could weaken the OTP+PKCE binding if logs are compromised. Prefer logging a non-sensitive identifier (e.g., a redacted placeholder or the derived codeChallenge if you need correlation).
if (result.error.code === 'token_reused') {
logger.audit.authn.tokenReused({
tokenId: codeVerifier,
context: { email },
})
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Use the extracted package for PKCE and OTP issue/verify so starter-kit stops maintaining a forked copy of that flow.
Map package error codes to the previous user-facing copy so rate-limit and invalid/expired failures stay actionable.
Bump @opengovsg/auth so failed OTP verifies can log the real attempt count instead of a placeholder.
Collapse non-rate-limit OTP errors to one message, avoid logging the PKCE verifier, and shrink the code-challenge validation sample.
The importer still pinned 7.9.0 after the catalog bump, which broke frozen installs in CI.
karrui
force-pushed
the
karrui/use-opengovsg-auth
branch
from
August 12, 2026 08:43
e196b17 to
eacdea4
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
@opengovsg/auth@0.0.0-snapshot-20260811091307VerificationTokenStoreadapter and wire login/verify throughcreateOtpAuthauth.utilsandlib/pkcenow covered by the packageTest plan
pnpm -C apps/web typecheckpnpm -C apps/web test:ci src/server/modules/auth/__tests__/auth.service.spec.ts src/validators/__tests__/auth.spec.ts