From 0835066bf0505ba51195c692c6a945f5105152f1 Mon Sep 17 00:00:00 2001 From: Morgan Date: Tue, 31 Oct 2023 01:57:08 -0700 Subject: [PATCH] doc: Remove async validation from useGenericAuth docs (#2022) --- packages/plugins/generic-auth/README.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/plugins/generic-auth/README.md b/packages/plugins/generic-auth/README.md index 2c81d1e66..701d790b1 100644 --- a/packages/plugins/generic-auth/README.md +++ b/packages/plugins/generic-auth/README.md @@ -175,7 +175,7 @@ type UserType = { const resolveUserFn: ResolveUserFn = async context => { /* ... */ } -const validateUser: ValidateUserFn = async params => { +const validateUser: ValidateUserFn = params => { /* ... */ } @@ -198,7 +198,11 @@ Then, in your resolvers, you can execute the check method based on your needs: const resolvers = { Query: { me: async (root, args, context) => { - await context.validateUser() + const validationError = context.validateUser() + if (validationError) { + throw validationError + } + const currentUser = context.currentUser return currentUser @@ -292,7 +296,7 @@ the `protect-all` and `protect-granular` mode: import { GraphQLError } from 'graphql' import { ValidateUserFn } from '@envelop/generic-auth' -const validateUser: ValidateUserFn = async ({ user }) => { +const validateUser: ValidateUserFn = ({ user }) => { // Now you can use the 3rd parameter to implement custom logic for user validation, with access // to the resolver data and information. @@ -321,7 +325,7 @@ Then, you use the `directiveNode` parameter to check the arguments: ```ts import { ValidateUserFn } from '@envelop/generic-auth' -const validateUser: ValidateUserFn = async ({ user, fieldAuthDirectiveNode }) => { +const validateUser: ValidateUserFn = ({ user, fieldAuthDirectiveNode }) => { // Now you can use the fieldAuthDirectiveNode parameter to implement custom logic for user validation, with access // to the resolver auth directive arguments. @@ -385,11 +389,7 @@ validation. ```ts import { ValidateUserFn } from '@envelop/generic-auth' -const validateUser: ValidateUserFn = async ({ - user, - executionArgs, - fieldAuthExtension -}) => { +const validateUser: ValidateUserFn = ({ user, executionArgs, fieldAuthExtension }) => { if (!user) { return new Error(`Unauthenticated!`) } @@ -397,7 +397,7 @@ const validateUser: ValidateUserFn = async ({ // You have access to the object define in the resolver tree, allowing to define any custom logic you want. const validate = fieldAuthExtension?.validate if (validate) { - await validate({ + return validate({ user, variables: executionArgs.variableValues, context: executionArgs.contextValue