fix: auto-detect secureCookie to match Auth.js cookie prefix #21
No reviewers
Labels
No labels
domain:backend
domain:devops
domain:frontend
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
forgejo_admin/westside-landing!21
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "20-bug-event-locals-accesstoken-always-null"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
event.locals.accessTokenalways being null by auto-detecting thesecureCookieparameter from the request URL protocol, matching Auth.js internal cookie-prefix logic__Secure-authjs.session-tokencookies, butgetToken()was looking forauthjs.session-token(no prefix)Changes
src/hooks.server.js: ChangedsecureCookie: falsetosecureCookie: isSecurewhereisSecureis derived fromevent.request.url.startsWith('https'), matching Auth.js internal auto-detection (@auth/core/lib/init.jsline 69)src/auth.js: Documentation-only -- added comments explaining token persistence across requests and the Keycloak access token expiration limitation (default 5 min, no auto-refresh, token rotation deferred)Test Plan
/admin/teams-- team data loads (no more "Basketball API not reachable")/teams-- team data loads for authenticated users__Secure-authjs.session-token(confirming HTTPS prefix)Review Checklist
Related
plan-2026-03-08-tryout-prep-- Phase 10b (Frontend admin draft board + coach filtered roster)Self-Review: PASS
Correctness: The core fix (
secureCookie: isSecurederived fromevent.request.url.startsWith('https')) matches Auth.js internal auto-detection logic (url.protocol === "https:"in@auth/core/lib/init.jsline 69). Cookie name and HKDF salt derivation are consistent between encode (Auth.js) and decode (getToken()).Verified:
@auth/core@0.41.1source confirmsgetToken()usesdefaultCookies(secureCookie ?? false).sessionToken.namefor both cookie lookup and saltdefaultCookies(true)produces__Secure-authjs.session-token, matching what the browser receives on HTTPSaccessTokenandrolesacross requests (Auth.js re-encodes the full token object returned by the callback)accessTokenby design)secureCookie: false, HTTPS (prod) getssecureCookie: trueNo issues found. Minimal, targeted fix.
PR #21 Frontend Review
BLOCKERS
None.
NITS
@ts-ignorecomments (lines 25, 28 inhooks.server.js) -- These suppress TypeScript errors for customevent.localsproperties. Consider defining a properApp.Localsinterface insrc/app.d.tsto get type safety onaccessToken. Non-blocking but would eliminate the need for suppression comments entirely.Token expiration note is documentation-only -- The comment in
auth.jscorrectly flags that Keycloak access tokens expire after 5 minutes and Auth.js does not auto-refresh. This is a known limitation, not a PR concern, but it should be tracked as a follow-up issue if not already.DOMAIN REVIEW
event.request.url.startsWith('https')is a trivial string check -- no performance concern.__Secure-prefix is a browser security feature that prevents cookie access over non-HTTPS connections. The previous hardcodedsecureCookie: falsewas silently breaking authentication on HTTPS deployments. The access token correctly remains server-side only (never attached to the session object sent to the browser)..gitignoreproperly excludes.envfiles.SOP COMPLIANCE
20-bug-event-locals-accesstoken-always-nullreferences issue #20)Closes #20present in PR bodyplan-2026-03-08-tryout-prep.envfiles committed (confirmed: all secret references use runtime$env/dynamic/private)PROCESS OBSERVATIONS
getToken()returns a token on HTTPS requests would prevent regression. This is a repo-wide gap, not specific to this PR.secureCookiefrom the request URL should be documented as a convention for any Auth.js + Tailscale funnel deployment, since all such sites will be HTTPS and encounter this same mismatch ifsecureCookieis hardcoded.VERDICT: APPROVED
Clean, minimal, correct bug fix. The root cause analysis is well-documented in both the PR body and inline comments. The change mirrors Auth.js's own internal detection logic, which is the right approach. No blockers.