NeverNull / gatsby-apollo-wpgraphql-jwt-starter

A gatsby starter, that should serve as an entry point for user authentication with WPGraphQL, JWT, Apollo and private routes.
MIT License
28 stars 6 forks source link

Error: GraphQL error: The JWT token could not be returned #2

Closed ivanjeremic closed 4 years ago

ivanjeremic commented 4 years ago

I'm not sure why the mutation is looking like this, Where is LoginInput! coming from?

    mutation LoginUser($input: LoginInput!) {
        login(input: $input) {
            user {
                jwtAuthToken
                jwtRefreshToken
                jwtAuthExpiration
                isJwtAuthSecretRevoked
                username
                nicename
            }
        }
    }

From the wpgraphql-jwt docs, I see authToken is used but here in this Boilerplate not

  login( input: {
    clientMutationId:"uniqueId"
    username: "your_login"
    password: "your password"
  } ) {
    authToken
    user {
      id
      name
    }
  }
}

If anyone can clarify this to me would be very thankful. Also, I hope to create a .env.development and putting my GRAPHQL_URL=https://mysite.com/graphql is the correct way to do it in Gatsby.

But I copied the Logic of this boilerplate into a CRA/Apollo app and I'm still not able to get a token.

henrikwirth commented 4 years ago

It is all still super experimental, therefore anything could still change. Just trying out a lot right now.

See the new commit and this file: https://github.com/NeverNull/gatsby-apollo-wpgraphql-jwt-starter/blob/master/src/components/LoginForm.js#L9-L19

henrikwirth commented 4 years ago

LoginInput comes from passing the input to the useMutation like:

const [loginUser, { data: loginData }] = useMutation(LOGIN_USER)

loginUser({
      variables: {
        input: {
          clientMutationId: getUuid(),
          username: fields.username,
          password: fields.password,
        },
      },
    })

Checkout Mutation docs of Apollo here: https://www.apollographql.com/docs/react/v3.0-beta/data/mutations/