Skip to content

Commit

Permalink
doc: Remove async validation from useGenericAuth docs (#2022)
Browse files Browse the repository at this point in the history
  • Loading branch information
rmtmckenzie authored Oct 31, 2023
1 parent b8fd06a commit 0835066
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions packages/plugins/generic-auth/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ type UserType = {
const resolveUserFn: ResolveUserFn<UserType> = async context => {
/* ... */
}
const validateUser: ValidateUserFn<UserType> = async params => {
const validateUser: ValidateUserFn<UserType> = params => {
/* ... */
}

Expand All @@ -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
Expand Down Expand Up @@ -292,7 +296,7 @@ the `protect-all` and `protect-granular` mode:
import { GraphQLError } from 'graphql'
import { ValidateUserFn } from '@envelop/generic-auth'

const validateUser: ValidateUserFn<UserType> = async ({ user }) => {
const validateUser: ValidateUserFn<UserType> = ({ user }) => {
// Now you can use the 3rd parameter to implement custom logic for user validation, with access
// to the resolver data and information.

Expand Down Expand Up @@ -321,7 +325,7 @@ Then, you use the `directiveNode` parameter to check the arguments:
```ts
import { ValidateUserFn } from '@envelop/generic-auth'

const validateUser: ValidateUserFn<UserType> = async ({ user, fieldAuthDirectiveNode }) => {
const validateUser: ValidateUserFn<UserType> = ({ user, fieldAuthDirectiveNode }) => {
// Now you can use the fieldAuthDirectiveNode parameter to implement custom logic for user validation, with access
// to the resolver auth directive arguments.

Expand Down Expand Up @@ -385,19 +389,15 @@ validation.
```ts
import { ValidateUserFn } from '@envelop/generic-auth'

const validateUser: ValidateUserFn<UserType> = async ({
user,
executionArgs,
fieldAuthExtension
}) => {
const validateUser: ValidateUserFn<UserType> = ({ user, executionArgs, fieldAuthExtension }) => {
if (!user) {
return new Error(`Unauthenticated!`)
}

// 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
Expand Down

0 comments on commit 0835066

Please sign in to comment.