Repository navigation
[haxcms-elements] Store request tokens returned by login, refresh and connection-test - #882
Merged
Merged
Conversation
HAXcms backends (haxcms-nodejs#71, haxcms-php#655) can omit userToken /
siteToken from connection-settings for anonymous page loads
(security.requireSessionForRequestTokens) and instead return them on
successful login, refresh and connection-test responses. The editor loads
connection-settings once, before login, so it has to pick them up from those
responses or token-protected calls drop all auth headers and login loops.
- haxcms-elements/lib/core/utils/session-request-tokens.js: extract tokens from
a response (top-level or { data }) and write them into appSettings in every
shape the editor reads: userToken / siteToken, getUserDataHeaders, and
appStore.headers. Nested objects are replaced, never mutated; missing
tokens never clear existing ones.
- jwt-login: after a successful login or refresh, re-broadcast any tokens in
the response as `jwt-login-session-tokens` ({ userToken?, siteToken?,
context }), dispatched before the jwt changes so refresh retries already
have them.
- AppHaxBackendAPI (dashboard) and haxcms-backend-nodejs / -php (site
editor): apply tokens from that event and from authenticated
connection-test responses to globalThis.appSettings, store.appSettings and
the system / site API registries.
- tests: helper unit tests, jwt-login event + ordering, AppHaxBackendAPI
connection-test and event handling.
Works with backends in either mode: when connection-settings still sends the
tokens, the responses carry the same values.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013J4JEf3WfrBgaePbuRC7uF
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
This was referenced Oct 19, 2026
This branch was successfully deployed
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Follow-up to the session-hardening PRs (haxtheweb/haxcms-nodejs#71, haxtheweb/haxcms-php#655). This is step 1 of 2 for turning on
security.requireSessionForRequestTokens.Why
The backends can now leave
siteToken/userTokenout ofconnection-settingsfor anonymous page loads. Instead, login, refresh and connection-test responses return them. The editor loadsconnection-settingsonce, before login. If it doesn't pick the tokens up from those responses, the API registries drop all auth headers on token-protected calls and in-page login loops (401 → "Auth loop detected").What changes
haxcms-elements/lib/core/utils/session-request-tokens.js(new){ data }). Writes them intoappSettingsin every shape the editor reads:userToken/siteToken,getUserDataHeaders[userTokenHeader], andappStore.headers['X-HAXCMS-Site-Token']. Nested objects are replaced, never mutated. A missing token never clears an existing one.jwt-login/jwt-login.jsjwt-login-session-tokens({ userToken?, siteToken?, context }). It fires before the jwt changes, so a refresh retry already has the tokens. Nothing fires when neither token is present, or for logout.app-hax/lib/v2/AppHaxBackendAPI.js(dashboard)globalThis.appSettings,store.appSettingsand the system API registry.haxcms-elements/lib/core/backends/haxcms-backend-nodejs.js/-php.js(site editor)It works against backends in either mode. Where
connection-settingsstill sends tokens, the responses carry the same values, so merging this changes nothing for today's deployments.Tests
haxcms-elements/test/session-request-tokens.test.js, covering extraction shapes, every write target, no mutation, no clearing, and no-change detection.this.appSettings,store.appSettings,globalThis.appSettingsand the registry. A failed connection-test applies nothing. The event handler works, and the no-token case is a no-op.Local runs (web-test-runner, Chromium):
End-to-end with the backend flag on: I copied these files into a scratch copy of haxcms-nodejs's
src/public/buildand ran haxcms-nodejs'snpm run test:e2eagainst the companion backend PR, whererequireSessionForRequestTokensdefaults to on. Results are in the companion PR.Merge order
build/folders; the managed packaging step, not by hand).siteTokentoo. They must land after step 1's build is in each backend.jwt-login.test.jsandapp-hax-backend-api.test.jswere already not Prettier-clean onmaster. I left their existing formatting alone so the diff only shows the new tests.https://claude.ai/code/session_013J4JEf3WfrBgaePbuRC7uF
Generated by Claude Code