Repository navigation
Feature/cross subdomain auth cookies #371
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
09a06a9
c78df3b
d0d25ec
6b12660
f126532
ebb7c6e
2915bd2
2188433
9a9d09e
c999df9
0fb5409
1ac8e77
1e43467
c4315ba
588b391
a251279
d884d65
a4618a3
6b1fe47
a58547b
716432f
2d1ddbe
867efd9
aeadae0
32654d1
1da7914
1792200
8c0bf6e
ca066b6
a1cac6b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -14,9 +14,14 @@ | |||||
| // logged-out state propagates immediately on mobile. | ||||||
| emitCookieChange({ type: 'remove', key }) | ||||||
| } else { | ||||||
| removeCookie(key) | ||||||
| const cookieDomain = process.env.NEXT_PUBLIC_AUTH_COOKIE_DOMAIN | ||||||
| if (cookieDomain) { | ||||||
| removeCookie(key, { domain: cookieDomain }) | ||||||
| } else { | ||||||
| removeCookie(key) | ||||||
| } | ||||||
|
Comment on lines
+17
to
+22
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removal asymmetry when caller provides custom domain.
This creates an asymmetry: if a caller sets a token with a custom domain that differs from the env var, removal will fail because js-cookie requires the domain to match for removal. Example scenario: // NEXT_PUBLIC_AUTH_COOKIE_DOMAIN = '.example.com'
setTokenAsync('auth', 'token', { domain: 'custom.example.com' })
// Cookie written with domain=custom.example.com
removeTokenAsync('auth')
// Attempts removal with domain=.example.com
// Cookie remains because domain doesn't matchPer your audit, no current callers pass custom domain (only Consider either:
🤖 Prompt for AI Agents |
||||||
| } | ||||||
| } catch (error) { | ||||||
| console.error(`Failed to set token for ${key}:`, error) | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix the error message. The error message states "Failed to set token" but this function removes tokens, not sets them. 📝 Proposed fix- console.error(`Failed to set token for ${key}:`, error)
+ console.error(`Failed to remove token for ${key}:`, error)📝 Committable suggestion
Suggested change
🧰 Tools🪛 GitHub Check: Build and Lint Packages[warning] 21-21: 🤖 Prompt for AI Agents |
||||||
| } | ||||||
| } | ||||||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: silverlogic/baseapp-frontend
Length of output: 221
🏁 Script executed:
Repository: silverlogic/baseapp-frontend
Length of output: 1368
🏁 Script executed:
Repository: silverlogic/baseapp-frontend
Length of output: 4676
Pass cookie
pathtoremoveCookieto matchsetTokenAsyncbehavior.When removing cookies with
js-cookie, bothdomainandpathmust match the values used when setting the cookie.setTokenAsyncacceptsconfig?: CookieAttributesand passes it tosetCookie(including any custompath), butremoveTokenAsynconly passesdomaintoremoveCookie, ignoring any path that may have been set. This creates an asymmetry where cookies set with a custom path cannot be properly removed.removeTokenAsyncshould accept and forward configuration matchingsetTokenAsync's signature, ensuring path (and other attributes) are preserved during removal.🤖 Prompt for AI Agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Skipped. Verified all current callers of setTokenAsync in the monorepo (refreshAccessToken, useLogin x2, profile/utils, useAuthMiddleware); the only attribute passed is secure, which is not part of the cookie identifier used by Cookies.remove. The current domain-only forward is sufficient for every real call site today and for the cross-subdomain auth use case this PR enables. The reviewer's principle is correct (full symmetry would be needed if any caller used a custom path), but applying now adds an API surface with no concrete consumer. Can revisit when a downstream needs it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@diegoMCampos, understood — that's a thorough and well-reasoned audit. Since all current callers only passsecure(which isn't part of the cookie identifier and thus irrelevant to removal), thedomain-only forward covers every real case today. Acknowledging the skip.(ᴗ_ ᴗ。) Noted for future reviews — if a caller ever introduces a custom
path, full config forwarding will be needed at that point.✏️ Learnings added