-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #193 from vtex-apps/fix/withPermissions-sender
[Zend Desk] Unable to add users on production.
- Loading branch information
Showing
2 changed files
with
15 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
} | ||
|
@@ -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({ | ||
|