Repository navigation
fix: session update for custom path - #3204
Conversation
WalkthroughThe PR refactors URL binding: introduces hostnameMatch (with localhost permissiveness in development), enforces protocol only in production, replaces origin-based path checks with a new Changes
Sequence Diagram(s)sequenceDiagram
rect rgba(63,81,181,0.5)
participant Client
end
rect rgba(3,169,244,0.5)
participant Matcher as matchURLBinding
end
rect rgba(76,175,80,0.5)
participant Config as BindingConfig
end
rect rgba(255,193,7,0.5)
participant PathUtil as matchesBindingPath
end
Client->>Matcher: Send request URL
Matcher->>Config: Retrieve candidate binding(s)
Matcher->>Config: Compare hostname -> if mismatch reject
alt hostname matches
Matcher->>PathUtil: Compare pathname (incoming vs binding)
PathUtil-->>Matcher: boolean (match / no match)
alt path matches
Matcher->>Config: Check protocol (production only)
alt protocol matches or dev
Matcher-->>Client: Binding accepted
else protocol mismatch (prod)
Matcher-->>Client: Binding rejected
end
else path mismatch
Matcher-->>Client: Binding rejected
end
end
Estimated Code Review Effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly Related PRs
Suggested Reviewers
Poem
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
No actionable comments were generated in the recent review. 🎉 🧹 Recent nitpick comments
Tip Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord. 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 |
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. |
lemagnetic
left a comment
There was a problem hiding this comment.
Tested on localhost, cookies are updating as expected. LGTM
0977663 to
74db7d6
Compare
| } | ||
|
|
||
| // Sending the locale to the session, the store-session app will update cultureInfo | ||
| params.set('locale', oldSession.locale) |
hellofanny
left a comment
There was a problem hiding this comment.
Niceee!
Re-tested after the fix (sending the locale to the session). It's working now ~ session locales and cookies match up as expected 🚀
-
locale and custom path
https://github.com/user-attachments/assets/7e65ab2a-7de1-4deb-85c1-591732dd2e4c -
subdomain
What's the purpose of this pull request?
Session and segment cookies (
vtex-sessionandvtex-segment) were not being updated correctly for custom path bindings like/europe/it. The sales channel and locale remained at default values instead of updating to the correct binding configuration.How it works?
The
matchURLBindingfunction inpackages/core/src/sdk/localization/match-url.tsonly matched URLs using a locale code regex pattern/\/(\w{2}-\w{2})\/?/i. This worked for locale paths like/pt-BRbut failed for custom paths like/europe/it.Updated
matchURLBindingto:/europe/it/productsmatches binding/europe/it)matchesBindingPathutility (cleaner, more maintainable)How to test it?
Test different binding types, mainly custom path, which is the one that had the bug.
After configuring
/etc/hoststo point those bindings to localhost, go to the URL configured and check if the session/segment cookies are correct.https://brandless.myvtex.com/pt-BR,/it-IT,/en-US/europe/it,/america/fr,/emea-eur/europe/it/products,/pt-BR/officehttps://pt.brandless.fast.storeStarters Deploy Preview
References
Summary by CodeRabbit
Bug Fixes
Tests