-
Notifications
You must be signed in to change notification settings - Fork 30
Fix: Define cookie priority for order placed loader #1567
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: main
Are you sure you want to change the base?
Changes from all commits
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 | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -11,6 +11,37 @@ interface Props { | |||||||||||||||||||||
| orderId: string; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| /** | ||||||||||||||||||||||
| * Checkout cookies (CheckoutDataAccess + Vtex_CHKO_Auth) are set by VTEX right | ||||||||||||||||||||||
| * after an order is placed and are sufficient — and preferred — to access the | ||||||||||||||||||||||
| * order-placed page. The VtexIdclientAutCookie_* auth cookie can still be | ||||||||||||||||||||||
| * present in the browser even after it has expired, so sending it alongside the | ||||||||||||||||||||||
| * checkout cookies (or on its own when stale) causes the request to fail. | ||||||||||||||||||||||
| * Strategy: use checkout cookies when available; fall back to the auth cookie | ||||||||||||||||||||||
| * only when they are absent. | ||||||||||||||||||||||
| */ | ||||||||||||||||||||||
| function resolveOrderCookie(headers: Headers): string { | ||||||||||||||||||||||
| const all = getCookies(headers); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| const checkoutCookies = Object.fromEntries( | ||||||||||||||||||||||
| Object.entries(all).filter(([key]) => | ||||||||||||||||||||||
| key === CHECKOUT_DATA_ACCESS_COOKIE || key === VTEX_CHKO_AUTH | ||||||||||||||||||||||
| ), | ||||||||||||||||||||||
| ); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| if (Object.keys(checkoutCookies).length > 0) { | ||||||||||||||||||||||
| return stringify(checkoutCookies); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
Comment on lines
+32
to
+34
Contributor
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. Require both checkout cookies before choosing checkout-cookie mode. At Line 32, the condition Suggested fix- if (Object.keys(checkoutCookies).length > 0) {
+ const hasBothCheckoutCookies =
+ checkoutCookies[CHECKOUT_DATA_ACCESS_COOKIE] != null &&
+ checkoutCookies[VTEX_CHKO_AUTH] != null;
+
+ if (hasBothCheckoutCookies) {
return stringify(checkoutCookies);
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| const authCookies = Object.fromEntries( | ||||||||||||||||||||||
| Object.entries(all).filter(([key]) => | ||||||||||||||||||||||
| key.startsWith(VTEX_ID_CLIENT_COOKIE) | ||||||||||||||||||||||
| ), | ||||||||||||||||||||||
| ); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| return stringify(authCookies); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
Comment on lines
+42
to
+43
Contributor
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. Avoid sending an empty If neither checkout nor auth cookies are found, Suggested fix-function resolveOrderCookie(headers: Headers): string {
+function resolveOrderCookie(headers: Headers): string | undefined {
const all = getCookies(headers);
@@
- return stringify(authCookies);
+ return Object.keys(authCookies).length > 0 ? stringify(authCookies) : undefined;
}
@@
- const cookie = resolveOrderCookie(req.headers);
+ const cookie = resolveOrderCookie(req.headers);
+ const headers = cookie ? { cookie } : undefined;
@@
- }, {
- headers: { cookie },
- }).then((res) => res.json());
+ }, {
+ headers,
+ }).then((res) => res.json());
@@
- }, {
- headers: { cookie },
- }).then((res) => res.json());
+ }, {
+ headers,
+ }).then((res) => res.json());Also applies to: 55-55 🤖 Prompt for AI Agents |
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| /** | ||||||||||||||||||||||
| * @title Get Order Placed Order Details | ||||||||||||||||||||||
| * @description Should be used on order placed page, the user must be authenticated or have access to the order through permissions or cookies | ||||||||||||||||||||||
|
|
@@ -21,16 +52,7 @@ export default async function loader( | |||||||||||||||||||||
| ctx: AppContext, | ||||||||||||||||||||||
| ) { | ||||||||||||||||||||||
| const { vcsDeprecated } = ctx; | ||||||||||||||||||||||
| const cookies = Object.fromEntries( | ||||||||||||||||||||||
| Object.entries(getCookies(req.headers)).filter(([key]) => | ||||||||||||||||||||||
| key.startsWith(VTEX_ID_CLIENT_COOKIE) || | ||||||||||||||||||||||
| // these two cookies are set by VTEX after order is placed on checkout and are | ||||||||||||||||||||||
| // used to access the order placed page | ||||||||||||||||||||||
| key === CHECKOUT_DATA_ACCESS_COOKIE || | ||||||||||||||||||||||
| key === VTEX_CHKO_AUTH | ||||||||||||||||||||||
| ), | ||||||||||||||||||||||
| ); | ||||||||||||||||||||||
| const cookie = stringify(cookies); | ||||||||||||||||||||||
| const cookie = resolveOrderCookie(req.headers); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| const isOrderGroup = !orderId.includes("-"); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
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.
P1: This condition passes when only one of the two required checkout cookies (
CheckoutDataAccess,Vtex_CHKO_Auth) is present, skipping the auth-cookie fallback. Since VTEX requires both checkout cookies to grant access, a partial set will still cause the request to fail. Check that both cookies are present before choosing checkout-cookie mode.Prompt for AI agents