Learn how permissions work
todos
with id
, title
, and user_id
columns. We want users to only have access to their own todos. This is how we would do it:
user_id
must be equal (_eq
) to the authenticated user’s ID (x-hasura-user-id
).
x-hasura-user-id
?x-hasura-user-id
is a permission variable that is used to create permission rules. Permission Variables come from the session’s access token. You can add custom permission variables to create more complex permission rules unique to your project.
x-hasura-company-id
with path user.company.id
. Nhost Auth will get the value for x-hasura-company-id
by generating and running the following GraphQL query:
$.
when configuring them.
x-hasura-organization-ids
, the path should be, e.g., user.profile.organizations[*].id
.
This will result in the following GraphQL query internally:
users.metadata
column.
nhost.toml
as follows:
x-hasura-organization-id
:
user
when defined in nhost.toml
.x-hasura-role
header in the GraphQL request.
user
is the default role for authenticated users.
x-hasura-role = <role>
to the GraphQL request.
public
role.
id
nor user_id
, because they should not be inserted by the user. The id
is automatically generated by the database and user_id
is set using a column preset.user_id
to x-hasura-user-id
. This way, every new record’s user_id
value is set to the ID of the user making the request.id
is automatically generated by the database and the user_id
is automatically set to the user’s id using the user_id = x-hasura-user-id
column preset.
user_id
, _eq
and x-hasura-user-id
into the rule form. This means that in order for users to read data, the user ID value in the database row must be the same as the user ID in the access token.