Skip to content

Commit

Permalink
fix: provide correct tokens to clients
Browse files Browse the repository at this point in the history
  • Loading branch information
Matheus-Aguilar committed Jun 10, 2024
1 parent ad697a4 commit 7359649
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
## [Unreleased]

### Fixed

- Provide correct tokens to clients
- Add catalog-info.yaml

## [1.11.1] - 2023-12-15
Expand Down
4 changes: 2 additions & 2 deletions node/clients/Organizations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ export class OrganizationsGraphQLClient extends AppGraphQLClient {
},
},
{
headers: getTokenToHeader(this.context),
params: {
headers: getTokenToHeader(this.context),
locale: this.context.locale,
},
}
Expand All @@ -48,8 +48,8 @@ export class OrganizationsGraphQLClient extends AppGraphQLClient {
},
},
{
headers: getTokenToHeader(this.context),
params: {
headers: getTokenToHeader(this.context),
locale: this.context.locale,
},
}
Expand Down
2 changes: 1 addition & 1 deletion node/clients/StorefrontPermissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ export default class StorefrontPermissions extends AppGraphQLClient {
variables: {},
},
{
headers: getTokenToHeader(this.context),
params: {
headers: getTokenToHeader(this.context),
locale: this.context.locale,
},
}
Expand Down
19 changes: 13 additions & 6 deletions node/clients/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,22 @@ export class Clients extends IOClients {
}

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 {
'x-vtex-credential': ctx.authToken,
VtexIdclientAutCookie: token,
cookie: `VtexIdclientAutCookie=${token}`,
'x-vtex-session': sessionToken,
VtexIdclientAutCookie: adminToken,
cookie: allCookies,
...(sessionToken && {
'x-vtex-session': sessionToken,
}),
}
}

0 comments on commit 7359649

Please sign in to comment.