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 May 29, 2024
1 parent c7266fb commit 4420cc1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed

- Provide correct tokens to clients

## [2.5.2] - 2024-02-05

### Fixed
Expand Down
19 changes: 13 additions & 6 deletions node/clients/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,23 @@ import StorefrontPermissions from './storefrontPermissions'
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 ?? null
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,
}),
}
}

Expand Down

0 comments on commit 4420cc1

Please sign in to comment.