Next-auth: Config for setting up JWT with Hasura GraphQL service

Created on 30 Jul 2020  路  3Comments  路  Source: nextauthjs/next-auth

I have next-auth up and running locally with one provider, using JWT (without database session).
Next, I want to use the Jwt with Hasura for supported authentication and authorization.

Here is a step by step guide:
https://hasura.io/docs/1.0/graphql/manual/auth/authentication/jwt.html

Your question
I am trying to figure out next-auth config for my jwt-secret:

{
  "type": <optional-type-of-key>,
  "key": <optional-key-as-string>,
  "jwk_url": <optional-url-to-refresh-jwks>,
  "claims_namespace": <optional-key-name-in-claims>,
  "claims_namespace_path": <optional-json-path-to-the-claims>,
  "claims_format": <json|stringified_json>,
  "audience": <optional-string-or-list-of-strings-to-verify-audience>,
  "issuer": <optional-string-to-verify-issuer>
}

Instructions:
https://hasura.io/docs/1.0/graphql/manual/auth/authentication/jwt.html#configuring-jwt-mode

I intend to use jwt callback to set claims for Hasura authorization to work:

"https://hasura.io/jwt/claims": {
  "x-hasura-allowed-roles": ["editor","user", "mod"],
  "x-hasura-default-role": "user",
  "x-hasura-user-id": "1234567890",
  "x-hasura-org-id": "123",
  "x-hasura-custom": "custom-value"
}

Documentation feedback
Once, I have figured and got it working, I'd be happy to contribute to next-auth docs.

  • [ ] Found the documentation helpful
  • [ ] Found documentation but was incomplete
  • [x] Could not find relevant documentation
  • [ ] Found the example project helpful
  • [ ] Did not find the example project helpful
help wanted question

Most helpful comment

@SharadKumar I'm using NextAuth in a Next.js and Hasura application. I came across a similar solution and solved it in this way. Let me know if this helps you.

All 3 comments

@SharadKumar I'm using NextAuth in a Next.js and Hasura application. I came across a similar solution and solved it in this way. Let me know if this helps you.

Thank you @ghoshnirmalya

I have been able to to get JWT (without database) working with Hasura role-based authorization (JWT), with help from your boilerplate. So thank you and Ian.

@SharadKumar what do you mean by without database?

Was this page helpful?
0 / 5 - 0 ratings