Skip to content

Implement frontend dual-mode readiness for httpOnly cookie SIWE migration (Phase 2) - #371

Merged
Lakes41 merged 3 commits into
Adamantine-guild:mainfrom
NkechiOgbuji:feat/dual-auth-mode-cookie-readiness
Jul 29, 2026
Merged

Implement frontend dual-mode readiness for httpOnly cookie SIWE migration (Phase 2)#371
Lakes41 merged 3 commits into
Adamantine-guild:mainfrom
NkechiOgbuji:feat/dual-auth-mode-cookie-readiness

Conversation

@NkechiOgbuji

Copy link
Copy Markdown
Contributor

Close #304

Description

This PR introduces a feature-flagged authentication layer that prepares the frontend for the planned migration from JavaScript-accessible bearer tokens to secure httpOnly cookies, while preserving the existing authentication flow by default.

Instead of performing a hard cutover, this implementation adds support for both authentication modes so the frontend can be tested against the upcoming backend changes without affecting current deployments. Existing bearer-token authentication remains the default behavior, while cookie mode can be enabled through NEXT_PUBLIC_AUTH_MODE=cookie when the backend is ready.

What changed

  • Added a new NEXT_PUBLIC_AUTH_MODE configuration with validation and a default value of bearer.
  • Introduced a cookie-aware session flow by implementing isSessionActive() to verify authentication without relying on a JavaScript-readable access token.
  • Updated the API client so bearer tokens are optional and only attached when running in bearer mode.
  • Refactored the SIWE authentication provider to support both authentication strategies while preserving the current user experience.
  • Ensured cookie mode no longer depends on reading or writing authentication tokens to sessionStorage, while keeping existing cross-tab authentication events intact.
  • Extended the mock API to simulate cookie-based authentication, allowing the new flow to be tested without requiring backend support.
  • Added comprehensive unit and end-to-end tests covering both bearer and cookie authentication modes to ensure backward compatibility and validate the new behavior.
  • Updated the HTTP-only cookie migration guide and README to document the new dual-mode implementation and configuration.

Why this approach

The migration plan documented in the repository assumes backend cookie support is already available. Introducing a dual-mode authentication layer reduces deployment risk by allowing the frontend and backend to be rolled out independently. Teams can enable cookie mode only when the backend is ready, while existing environments continue using the current bearer-token implementation without any behavioral changes.

This approach provides a safe migration path, simplifies testing across environments, and makes the eventual transition to secure httpOnly cookies much easier with minimal future code changes.

@Lakes41

Lakes41 commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Do resolve conflicts @NkechiOgbuji

@Lakes41
Lakes41 merged commit 56c0a92 into Adamantine-guild:main Jul 29, 2026
1 check passed
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.

Implement frontend dual-mode readiness for httpOnly cookie SIWE migration (Phase 2)

2 participants