Conversation
|
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Make journey-client and oidc-client importable and usable in Node.js/SSR
environments by eliminating eager browser global references and decoupling
PKCE generation from sessionStorage.
Storage: Replace eager sessionStorage/localStorage references with lazy
globalThis access via getBrowserStorage(). Add configurable storage option
to JourneyClientConfig so SSR callers can provide a custom noop adapter.
PKCE: Decouple generation from storage — createAuthorizeUrl now returns
{ url, verifier, state } instead of writing to sessionStorage. Callers
persist PKCE values however they choose (cookies, server session, etc.).
Token exchange accepts optional pkceValues parameter to skip sessionStorage.
Guard redirect() with typeof window check for server environments.
Export createJourneyObject for client-side step reconstitution.
SvelteKit PoC in e2e/svelte-app demonstrates the full flow:
server-side journey start, client-side credential submission,
server-side PKCE authorize URL generation with cookie-based verifier
persistence, and server-side token exchange against the AM mock API.
Summary
This is a complete proof of concept — not finished work. It demonstrates the changes needed to make
journey-clientandoidc-clientwork in server-side rendering environments (SvelteKit, Next.js, etc.).Problem
@forgerock/storageeagerly referencessessionStorage/localStorageglobals, crashing on import in Node.jscreateAuthorizeUrlcouples PKCE generation withsessionStorage, preventing server-side authorize URL creationwindow.location.assign()inredirect()has no server guardChanges
Storage (
@forgerock/storage)globalThisaccess viagetBrowserStorage()type: 'custom'with a no-op adapter — no new types neededJourney Client (
@forgerock/journey-client)storageconfig toJourneyClientConfig(defaults to sessionStorage)redirect()withtypeof windowcheckcreateJourneyObjectfor client-side step reconstitution after SSROIDC / PKCE (
@forgerock/sdk-oidc,@forgerock/oidc-client)createAuthorizeUrlnow returns{ url, verifier, state }instead of writing to sessionStoragetoken.exchange()accepts optionalpkceValuesparameter to skip sessionStorage lookupSvelteKit PoC (
e2e/svelte-app)start()→ SSR-rendered login formnext()Test plan
nx run storage:test— 21 tests passnx run journey-client:test— 193 tests passnx run sdk-oidc:test— 26 tests passnx run oidc-client:test— 21 tests passnx run davinci-client:test— 226 tests passam-mock-api:serve+vite devine2e/svelte-app, verify SSR rendering and token exchange