From 597f64fd8010d167366e9e2a64f9fca8353427d7 Mon Sep 17 00:00:00 2001 From: Matheus-Aguilar Date: Fri, 7 Jun 2024 16:36:47 -0300 Subject: [PATCH 1/3] fix: provide correct tokens to clients --- node/clients/Organizations.ts | 2 +- node/clients/index.ts | 20 ++++++++++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/node/clients/Organizations.ts b/node/clients/Organizations.ts index fda4e7d..bd1d427 100644 --- a/node/clients/Organizations.ts +++ b/node/clients/Organizations.ts @@ -74,8 +74,8 @@ export class OrganizationsGraphQLClient extends AppGraphQLClient { return this.graphql.query( { query, variables, extensions }, { + headers: getTokenToHeader(this.context), params: { - headers: getTokenToHeader(this.context), locale: this.context.locale, }, } diff --git a/node/clients/index.ts b/node/clients/index.ts index d430c12..a3ebe4b 100644 --- a/node/clients/index.ts +++ b/node/clients/index.ts @@ -12,15 +12,23 @@ import { Schema } from './schema' import VtexId from './vtexId' export const getTokenToHeader = (ctx: IOContext) => { - const token = - ctx.storeUserAuthToken ?? ctx.adminUserAuthToken ?? ctx.authToken + const adminToken = ctx.adminUserAuthToken ?? ctx.authToken + const userToken = ctx.storeUserAuthToken + const { sessionToken, account } = ctx - const { sessionToken } = ctx + let allCookies = `VtexIdclientAutCookie=${adminToken}` + + if (userToken) { + allCookies += `; VtexIdclientAutCookie_${account}=${userToken}` + } return { - VtexIdclientAutCookie: token, - cookie: `VtexIdclientAutCookie=${token}`, - 'x-vtex-session': sessionToken ?? '', + 'x-vtex-credential': ctx.authToken, + VtexIdclientAutCookie: adminToken, + cookie: allCookies, + ...(sessionToken && { + 'x-vtex-session': sessionToken, + }), } } From 92796fe5ecb4732d492617365ed77774fc043edb Mon Sep 17 00:00:00 2001 From: Matheus-Aguilar Date: Fri, 7 Jun 2024 16:49:20 -0300 Subject: [PATCH 2/3] chore: update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 12dd5bc..c4393dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +- Provide correct tokens to clients + ## [1.40.6] - 2024-05-28 ### Changed From ef70ec38de7ff1e6682ec835329eeacaa2f662c5 Mon Sep 17 00:00:00 2001 From: Matheus-Aguilar Date: Fri, 7 Jun 2024 17:16:44 -0300 Subject: [PATCH 3/3] chore: add fix to changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c4393dd..fa7e1c1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +### Fixed - Provide correct tokens to clients ## [1.40.6] - 2024-05-28