Skip to content

Commit

Permalink
fix: provide correct tokens to clients (#49)
Browse files Browse the repository at this point in the history
* fix: provide correct tokens to clients

* fix: remove nullish returning null
  • Loading branch information
Matheus-Aguilar authored Jun 10, 2024
1 parent c7266fb commit 834a40c
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
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 834a40c

Please sign in to comment.