Skip to content

fix: align password-protection vocabulary in v3 (unlock, not login) - #3404

Merged
eduardoformiga merged 2 commits into
3.xfrom
fix/password-protection-vocabulary
Jun 30, 2026
Merged

eduardoformiga merged 2 commits into
3.xfrom
fix/password-protection-vocabulary

Conversation

@vlaux

@vlaux vlaux commented Jun 23, 2026 •

Copy link
Copy Markdown
Contributor

FAS-1151

Summary

  • Ports vocabulary changes from v4 (f4ed151 / feat: Password Protection (v4) #3276) to v3 to fix a cookie name inconsistency with an external application
  • Renames __fs_auth_token → __fs_password_protection (the critical fix)
  • Aligns all related file names, class/method names, URLs, and UI copy to the unlock domain

Changes

Old (v3) New
__fs_auth_token (cookie) __fs_password_protection
AuthenticationService PasswordProtectionService
authenticateRequest() checkStoreProtection()
authentication-service.ts password-protection-service.ts
loginResponse.ts unlockResponse.ts
LoginResponse / isLoginResponse UnlockResponse / isUnlockResponse
pages/api/fs/auth/login pages/api/fs/password-protection/unlock
pages/fs-auth-login/ pages/password-protection/
Button label: Login Unlock
Input id: fs-auth-password password-protection-input

Context

The vocabulary inconsistency between v3 and v4 was causing issues in another application reading the auth cookie by name. This PR brings v3 in sync with the v4 refactor that was already merged (#3276).

Test plan

  • Unit tests pass (pnpm test in packages/core)
  • Middleware correctly redirects to /password-protection when store is protected
  • Unlock page posts to /api/fs/password-protection/unlock and sets __fs_password_protection cookie on success
  • External application consuming the cookie reads it correctly with the new name

🤖 Generated with Claude Code

Summary by CodeRabbit

Summary by CodeRabbit

Release Notes

  • Refactor
    • Switched store access checks from authentication-based protection to password-protection-based validation.
    • Updated the session protection service, including cookie name and renewal behavior.
    • Updated the unlock flow terminology and payload validation to use an unlock-specific response.
    • Adjusted middleware redirect behavior and cookie propagation to match the new protection flow.
  • New Features
    • Added the password-protection unlock page flow (Unlock submission + unlock API).
  • Tests
    • Updated password-protection service tests to match new cookies, redirects, and fail-close behavior.

Ports the vocabulary changes from v4 (f4ed151) to v3 to fix the
cookie name inconsistency (`__fs_auth_token` → `__fs_password_protection`)
and align all related identifiers, file names, URLs, and UI copy.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@vlaux
vlaux requested a review from a team as a code owner June 23, 2026 19:59
@vlaux
vlaux requested review from lariciamota and ommeirelles and removed request for a team June 23, 2026 19:59
@vtex-pr-sentinel

vtex-pr-sentinel Bot commented Jun 23, 2026 •

Copy link
Copy Markdown

🛡️ SDD Check — action required

I couldn't detect an SDD in this PR. Please check one option below (requires write access to the repo):

  • SDD lives in another PR — paste the SDD PR URL here:
  • This PR doesn't need an SDD
  • SDD applies, but I'm not adopting it in this PR

@coderabbitai

coderabbitai Bot commented Jun 23, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: c169258b-4419-4c38-8004-6eea82b0825e

📥 Commits

Reviewing files that changed from the base of the PR and between e8a6ffa and aa70bce.

📒 Files selected for processing (1)
  • packages/core/src/server/password-protection-service.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/core/src/server/password-protection-service.ts

Walkthrough

Renames AuthenticationService to PasswordProtectionService, updates the cookie name from __fs_auth_token to __fs_password_protection, renames authenticateRequest to checkStoreProtection, replaces LoginResponse/isLoginResponse with UnlockResponse/isUnlockResponse, updates the middleware matcher, unlock page UI, and migrates all tests accordingly.

Changes

Password Protection Rename

Layer / File(s) Summary
PasswordProtectionService: class, cookie, types, and methods
packages/core/src/server/password-protection-service.ts
Renames COOKIE_NAME to __fs_password_protection, AuthResult to StoreProtectionResult, AuthenticationService to PasswordProtectionService, authenticateRequest to checkStoreProtection (delegating to handleProtectionCheck), and redirectToLogin to redirectToUnlockPage targeting /password-protection.
UnlockResponse type and isUnlockResponse guard
packages/core/src/utils/unlockResponse.ts
Renames LoginResponse to UnlockResponse and isLoginResponse to isUnlockResponse, adding a hasUnlockResponseField check requiring at least one optional field to be present before accepting the shape.
Middleware: swap to PasswordProtectionService and update matcher
packages/core/src/middleware.ts
Replaces AuthenticationService.authenticateRequest with PasswordProtectionService.checkStoreProtection, updates cookie-copy source to storeProtectionResult.response.cookies, and changes config.matcher to exclude password-protection instead of fs-auth-login.
API unlock endpoint: imports and handler type
packages/core/src/pages/api/fs/password-protection/unlock.ts
Switches COOKIE_NAME and TOKEN_TTL_SECONDS imports to password-protection-service, adds UnlockResponse import, and updates the Next.js handler generic from LoginResponse to UnlockResponse.
Password protection unlock page UI and SCSS
packages/core/src/pages/password-protection/index.tsx, packages/core/src/pages/password-protection/password-protection.module.scss
Retargets fetch to /api/fs/password-protection/unlock, validates response with isUnlockResponse, updates CSS class to fsPasswordProtection, changes input id, and changes submit button label from "Login" to "Unlock".
Test suite migration to PasswordProtectionService
packages/core/test/server/password-protection-service.test.ts
Updates all imports, describe block, service invocations, cookie name assertions (__fs_password_protection), and redirect location expectations from the prior auth flow to PasswordProtectionService.checkStoreProtection.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • vtex/faststore#3276: Directly part of the same refactor introducing PasswordProtectionService, __fs_password_protection cookies, and the /api/fs/password-protection/unlock route.
  • vtex/faststore#3347: Also modifies packages/core/src/middleware.ts redirect and matcher behavior, on which this PR's middleware changes build directly.

Suggested reviewers

  • ommeirelles
  • eduardoformiga

Poem

🔐 No more "login", now we say "unlock",
The cookie swapped names around the clock.
AuthenticationService bows out with grace,
PasswordProtectionService takes its place.
A rename dance, clean and on the dot —
Same logic flows, just a brand-new slot! 🗝️

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: aligning password-protection vocabulary from login/auth terminology to unlock/password-protection terminology, which is the core objective of this PR.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/password-protection-vocabulary

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codesandbox-ci

codesandbox-ci Bot commented Jun 23, 2026 •

Copy link
Copy Markdown

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
packages/core/src/server/password-protection-service.ts (1)

264-273: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Leftover loginUrl name in renamed helper.

Since this PR is all about unifying the unlock/password-protection vocabulary, the local loginUrl inside redirectToUnlockPage is the last bit of login lingo hiding out. Renaming it keeps the helper internally consistent.

♻️ Proposed rename
   private redirectToUnlockPage(request: NextRequest): NextResponse {
-    const loginUrl = new URL('/password-protection', request.url)
+    const unlockUrl = new URL('/password-protection', request.url)
     const returnTo = `${request.nextUrl.pathname}${request.nextUrl.search}`
-    loginUrl.searchParams.set('returnTo', returnTo)
+    unlockUrl.searchParams.set('returnTo', returnTo)
 
-    const response = NextResponse.redirect(loginUrl)
+    const response = NextResponse.redirect(unlockUrl)
     response.headers.set('Cache-Control', 'no-store')
 
     return response
   }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/core/src/server/password-protection-service.ts` around lines 264 -
273, The local variable `loginUrl` in the `redirectToUnlockPage` method uses
"login" terminology which conflicts with the PR's vocabulary unification to use
"unlock"/"password-protection" terms. Rename the `loginUrl` variable to
`unlockUrl` throughout the method to maintain internal consistency with the
method name and the overall vocabulary changes in this PR.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@packages/core/src/server/password-protection-service.ts`:
- Around line 264-273: The local variable `loginUrl` in the
`redirectToUnlockPage` method uses "login" terminology which conflicts with the
PR's vocabulary unification to use "unlock"/"password-protection" terms. Rename
the `loginUrl` variable to `unlockUrl` throughout the method to maintain
internal consistency with the method name and the overall vocabulary changes in
this PR.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 23ebfbaf-5aa9-4513-9d4a-5fa9430ab391

📥 Commits

Reviewing files that changed from the base of the PR and between b2ec321 and e8a6ffa.

📒 Files selected for processing (7)
  • packages/core/src/middleware.ts
  • packages/core/src/pages/api/fs/password-protection/unlock.ts
  • packages/core/src/pages/password-protection/index.tsx
  • packages/core/src/pages/password-protection/password-protection.module.scss
  • packages/core/src/server/password-protection-service.ts
  • packages/core/src/utils/unlockResponse.ts
  • packages/core/test/server/password-protection-service.test.ts

@pkg-pr-new

pkg-pr-new Bot commented Jun 23, 2026

Copy link
Copy Markdown

Open in StackBlitz

@faststore/api

yarn add https://pkg.pr.new/vtex/faststore/@faststore/[email protected]

@faststore/cli

yarn add https://pkg.pr.new/vtex/faststore/@faststore/[email protected]

@faststore/components

yarn add https://pkg.pr.new/vtex/faststore/@faststore/[email protected]

@faststore/core

yarn add https://pkg.pr.new/vtex/faststore/@faststore/[email protected]

@faststore/graphql-utils

yarn add https://pkg.pr.new/vtex/faststore/@faststore/[email protected]

@faststore/lighthouse

yarn add https://pkg.pr.new/vtex/faststore/@faststore/[email protected]

@faststore/sdk

yarn add https://pkg.pr.new/vtex/faststore/@faststore/[email protected]

@faststore/ui

yarn add https://pkg.pr.new/vtex/faststore/@faststore/[email protected]

commit: aa70bce

@vlaux
vlaux requested a review from eduardoformiga June 26, 2026 20:45

@renatomaurovtex renatomaurovtex left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review — fix: align password-protection vocabulary in v3 (unlock, not login) (base 3.x)

Reviewed the full diff. This is a faithful backport of the v4 #3276 vocabulary refactor to v3: rename AuthenticationService→PasswordProtectionService, authenticateRequest→checkStoreProtection, handleNoAuth→handleProtectionCheck, redirectToLogin→redirectToUnlockPage, the /fs-auth-login→/password-protection page + /api/fs/auth/login→/api/fs/password-protection/unlock API routes, and the critical cookie rename __fs_auth_token→__fs_password_protection. Tests were renamed and all cookie/redirect assertions updated to the new names, and the middleware matcher exclusion was updated in lockstep (fs-auth-login→password-protection). The fail-close-to-unlock behavior is preserved across every branch (status fetch fail, non-ok, expired-renew fail). Mechanically clean and well-covered.

🟠 Cookie rename invalidates live protection sessions on deploy
Renaming __fs_auth_token→__fs_password_protection means every shopper currently holding a valid __fs_auth_token is treated as unauthenticated on the first request after deploy and bounced to /password-protection. The renew/status flow immediately re-issues the new cookie, so it's a one-time re-unlock, not a loop — but it IS a visible UX blip for protected stores. Please call this out in the release notes for the v3 line.

🟠 External-consumer coordination (the actual motivation)
The PR rationale is that an external app reads this cookie by name. The rename only fixes the inconsistency if that consumer is updated to read __fs_password_protection (or both names during a transition) and deployed around the same time. Otherwise this rename breaks the consumer in the opposite direction. Confirm the consuming app's rollout is sequenced with this merge.

🟡 isUnlockResponse adds stricter validation (not a pure rename)
Beyond the rename, isUnlockResponse now requires hasUnlockResponseField (at least one of success/redirectUrl/error defined), so an empty {} body that previously passed isLoginResponse now fails → the unlock page shows "Service temporarily unavailable". This looks intentional (an empty body isn't a meaningful unlock response, and the handler returns {success, redirectUrl} on success / {error} on failure), but it's a behavior change worth confirming matches the v4 #3276 implementation byte-for-byte so v3/v4 stay aligned.

💬 Nits

  • The page component is still named PasswordProtectionLogin (function identifier) though everything else moved off "login" — cosmetic, default export so no external impact.
  • redirectToUnlockPage keeps Cache-Control: no-store on the redirect — correct, preserved.

CI: FastStore build/test + codesandbox green; UI Tests pending (Chromatic baselines to accept — expected for the SCSS class rename).

Verdict: Approved with comments. No code blockers — the gating items are operational: sequence the external consumer + cookie-rename and note the one-time re-unlock in the v3 release notes.

@eduardoformiga
eduardoformiga merged commit 30222fc into 3.x Jun 30, 2026
6 checks passed
@eduardoformiga
eduardoformiga deleted the fix/password-protection-vocabulary branch June 30, 2026 15:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants