Creating Users
Users are created using the sign-up or sign-in flows described under Supported Methods.- Avoid creating users directly via GraphQL or the database, unless you are importing users from an external system.
- Avoid modifying the database schema for the
auth.users
table. - Avoid modifying the GraphQL root queries or fields for any of the tables in the
auth
schema.
- Add and remove your GraphQL relationships for the
users
table and other tables in theauth
schema. - Create, edit and delete permissions for the
users
table and other tables in theauth
schema.
Roles
Each user has one default role and a list of allowed roles. These roles are used to resolve permissions for requests to GraphQL and Storage. When the user makes a request, only one role is used to resolve permissions. The default role is used if no role is explicitly specified. Users can only make requests using the default role or one of the allowed roles.Default Role
The default role is used when no role is specified in the request. By default, users’ default role isuser
.
You can change what the default role for new users should be at Settings -> Roles and Permissions.
Allowed Roles
Allowed roles are roles the user is allowed to use when making a request. Usually, you would change the role fromuser
(the default role) to some other role because you want to use a different role to resolve permissions for a particular request.
By default, users have two allowed roles:
user
(default)me
Assign Allowed Roles
It’s possible to give users a subset of allowed roles during signup. Example: Only set theuser
role (exclude the me
role) for the user’s allowed roles:
Set Role for GraphQL Requests
When no role is specified, the user’s default role will be used:x-hasura-role
header, like this:
Metadata
You can store custom information about the user in themetadata
column of the users
table. The metadata
column is of type JSONB so any JSON data can be stored.
Example: Add metadata to a user during sign-up:
Get User Information using GraphQL
Example: Get all users.Import Users
If you have users in a different system, you can import them into Nhost. When importing users you should insert the users directly into the database instead of using the authentication endpoints (/signup/email-password
) to avoid sending unnecessary transactional emails.