Skip to content

Commit

Permalink
Merge pull request #193 from vtex-apps/fix/withPermissions-sender
Browse files Browse the repository at this point in the history
[Zend Desk] Unable to add users on production.
  • Loading branch information
rbussola authored Feb 21, 2025
2 parents 57e8edf + 31ffcfb commit 81bea9b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 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](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Fixed

- Bug fix on `withPermissions` directive to allow the use of the `sender` directive

## [0.63.3] - 2025-01-28
### Fixed
- Fix return from `removeUserWithEmail`
Expand Down
22 changes: 11 additions & 11 deletions node/resolvers/directives/withPermissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ import { SchemaDirectiveVisitor } from 'graphql-tools'
import type StorefrontPermissions from '../../clients/storefrontPermissions'

export const getUserPermission = async (
storefrontPermissions: StorefrontPermissions
storefrontPermissions: StorefrontPermissions,
app = '[email protected]'
) => {
const result = await storefrontPermissions.checkUserPermission(
'[email protected]'
)
const result = await storefrontPermissions.checkUserPermission(app)

return result?.data?.checkUserPermission ?? null
}
Expand All @@ -20,21 +19,22 @@ export class WithPermissions extends SchemaDirectiveVisitor {
public visitFieldDefinition(field: GraphQLField<any, any>) {
const { resolve = defaultFieldResolver } = field

field.resolve = async (
root: any,
args: any,
context: Context,
info: any
) => {
field.resolve = async (root: any, args: any, context: any, info: any) => {
const {
clients: { storefrontPermissions },
vtex: { adminUserAuthToken, logger },
} = context

const appClients = context.vtex as any
const sender =
context?.graphql?.query?.senderApp ??
context?.graphql?.query?.extensions?.persistedQuery?.sender ??
context?.request?.header['x-b2b-senderapp'] ??
undefined

appClients.storefrontPermissions = await getUserPermission(
storefrontPermissions
storefrontPermissions,
sender
).catch((error: any) => {
if (!adminUserAuthToken) {
logger.error({
Expand Down

0 comments on commit 81bea9b

Please sign in to comment.