Skip to content

Commit

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

* chore: update changelog

* chore: add fix to changelog
  • Loading branch information
Matheus-Aguilar authored Jun 11, 2024
1 parent 193852c commit a42ab64
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ 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

### Changed
Expand Down
2 changes: 1 addition & 1 deletion node/clients/Organizations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
}
Expand Down
20 changes: 14 additions & 6 deletions node/clients/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}),
}
}

Expand Down

0 comments on commit a42ab64

Please sign in to comment.