can you help me with this first - How to add ha...
# community
y
can you help me with this first - How to add hasura custom claims , how it will work out for JWT's , since docs mentioned below are using accessTokenPayload https://supertokens.com/docs/passwordless/hasura-integration/with-jwt#3--add-custom-claims-to-the-jwt
const result = await Passwordless.consumeCode({ userInputCode: otp, deviceId, preAuthSessionId }) const jwt = await Session.createJWT({ sub: result.user.id })
this is how i am creating JWT
so it will be like this -
Copy code
const jwt = await Session.createJWT({
    'https://hasura.io/jwt/claims': {
      'x-hasura-user-id': 'userId',
      'x-hasura-default-role': 'user',
      // do some custom logic to decide allowed roles
      'x-hasura-allowed-roles': [
        'user',
        'admin',
        'public',
        'public_user',
        'fr_admin'
      ]
    }
  }, 3600, { sub: result.user.id })
r
It should be:
Copy code
Session.createJWT({
    'https://hasura.io/jwt/claims': {
        'x-hasura-user-id': 'userId',
        'x-hasura-default-role': 'user',
        // do some custom logic to decide allowed roles
        'x-hasura-allowed-roles': [
            'user',
            'admin',
            'public',
            'public_user',
            'fr_admin'
        ]
    },
    sub: result.user.id
}, 3600);
The sub should be a part of the payload in the JWT. If you do not want that, you can omit the
sub
since you already have
x-hasura-user-id
@User
y
doing it like this -
Copy code
const jwt = await Session.createJWT({
    'https://hasura.io/jwt/claims': { // custom claims
      'x-hasura-supertoken-user-id': result.user.id,
      'x-hasura-user-id': 'userId',
      'x-hasura-default-role': 'user',
      // do some custom logic to decide allowed roles
      'x-hasura-allowed-roles': [
        'user',
        'admin',
        'public',
        'public_user',
        'fr_admin'
      ]
    }
  }, 3600)
adding
'x-hasura-supertoken-user-id': result.user.id,
r
makes sense.
y
this is the last piece in puzzle - able to successfully generate JWT token using Session.createJWT() with custom claims. Now i want to update https://supertokens.com/docs/passwordless/common-customizations/sessions/update-jwt-payload So how we can achieve that . I thing again call
await Session.createJWT
r
Yes. You would have to call
createJWT
again.
With the updated payload
3 Views