Custom user columns

You can add any custom columns to the users table.

Don't remove any predefined user columns.

#JWT claims

All custom columns on the users table can be added to the JWT-token as claims. These claims can then be used to set Hasura permissions.

As an example, let's say you have a company table and a company_id column to the users table. With that, you can now add company_id as an x-hasura-company-id key to your JWT claims.

Add custom claim to your JWT-token for Hasura

The new JWT-token contains the company_id as x-hasura-company-id.

{
  "https://hasura.io/jwt/claims": {
    "x-hasura-user-id": "f1126a1e-49e8-47b9-b9cc-e6dd5d568c7e",
    "x-hasura-allowed-roles": ["user", "me"],
    "x-hasura-default-role": "user",
    "x-hasura-company-id": "b3b70430-49db-4c06-b365-efb498e59913"
  },
  "iat": 1595247544,
  "exp": 1595247844
}

x-hasura-company-id can now be used as a permission variable for Hasura permissions.

In the example below, a user is allowed to select information about their own company (id = x-hasura-company-id).

#Set user field data on registration

You can specify what user fields that can be set during registration under Settings -> Authentication -> REGISTRATION CUSTOM FIELDS.

A popular field to let users set during registration is display_name that exist on the users table by default.

With nhost-js-sdk you can register a user, with the display_name like this:

import { auth } from "utils/nhost";

const email = "elon@tesla.com";
const password = "123123";
const displayName = "Elon Musk";

auth.register({
  email,
  password,
  options: {
    userData: {
      display_name: displayName,
    },
  },
});