Elevated Permissions
Require step-up re-authentication with a security key, TOTP, or a one-time password sent by email or SMS before sensitive actions using an elevated session claim.
elevated permissions step-up authentication MFA multi-factor TOTP OTP security key security re-authentication sensitive actionsIn some scenarios you may want to add an extra layer of security to perform certain actions or view certain data. For instance, you may wish to allow users to view their profile information after authenticating but require them to confirm changes to their profile by performing an extra verification step, such as touching a security key, entering a code from their authenticator app, or entering a one-time password sent to their email or phone.

This is accomplished by adding the claim x-hasura-auth-elevated: $user-id to the access token in response to the extra security challenge. With this new claim in mind you can start writing permissions that require this extra step.
It is important to keep in mind the claim is added to the access token so, for as long as you have that access token, you will have elevated access. Once the access token is renewed (due to expiration or any other reason), the claim will be lost and a new security challenge will be required to add it back.
Elevation methods
Section titled “Elevation methods”A signed-in user can elevate their session with any of the following methods. A method is only available when it is enabled for the project and the user has set it up:
| Method | Enabled with (nhost.toml) |
Available to the user when |
|---|---|---|
webauthn |
auth.method.webauthn.enabled |
They have at least one security key registered |
totp |
auth.totp.enabled |
They have activated TOTP on their account |
otp-email |
auth.method.otp.email.enabled |
They have a verified email address |
otp-sms |
auth.method.otp.sms.enabled |
They have a verified phone number |
Every method ends with the same result: a new session whose access token carries the x-hasura-auth-elevated claim. The JavaScript SDK stores that session automatically, so subsequent requests made with the same client use the elevated token. If you call the REST API directly, store the returned session, including its access and refresh tokens, and use the new access token for the protected request.
Discovering available methods
Section titled “Discovering available methods”Use GET /elevate to find out whether the current user needs to elevate their session, which methods they can use, and whether their session is already elevated:
const { body } = await nhost.auth.getElevationMethods();// {// elevationRequired: true,// methods: ['webauthn', 'totp', 'otp-email'],// sessionElevated: false// }elevationRequiredtells you whether the protected auth endpoints require an elevated session for this user under the current mode. It describes the policy, not the token, so it can betrueeven whensessionElevatedis alreadytrue.methodslists the methods enabled for the project and available to this user, even indisabledmode.sessionElevatedistruewhen the current access token has anx-hasura-auth-elevatedclaim matching its user ID, so you can skip the elevation step.
If elevationRequired is true, sessionElevated is false, and methods is empty, offer first-factor setup rather than a code prompt. The setup exceptions let the user register their first security key or activate TOTP before elevating.
Elevating a session
Section titled “Elevating a session”import { startAuthentication } from '@simplewebauthn/browser';
const response = await nhost.auth.elevateWebauthn();
const credential = await startAuthentication({ optionsJSON: response.body,});
await nhost.auth.verifyElevateWebauthn({ credential });await nhost.auth.elevateTotp({ otp: '123456',});// Send a one-time password to the user's email addressawait nhost.auth.elevateOTPEmail();
await nhost.auth.verifyElevateOTPEmail({ otp: '123456',});await nhost.auth.elevateOTPSms();
await nhost.auth.verifyElevateOTPSms({ otp: '123456',});All elevation endpoints require an Authorization: Bearer <access-token> header for the user being elevated; the SDK supplies it automatically. Email and SMS elevation use the signed-in user’s verified address or phone number, so neither the request nor the verification call accepts an email address or phone number.
Signing in, including completing a TOTP MFA challenge, does not itself add the elevated claim. Use the elevation endpoints for this extra step.
OTP codes and retries
Section titled “OTP codes and retries”- Email elevation codes expire after 10 minutes; SMS elevation codes expire after 5 minutes. Both are six-digit, single-use codes.
- Only one email or SMS OTP can be outstanding per user. Requesting another code, including for sign-in or a phone-number change, replaces the previous one. When offering resend or switching methods, prompt for the newest code.
- An incorrect or expired code returns
invalid-otp. After five incorrect attempts, the code is invalidated and verification returnsotp-too-many-attempts; request a new code to continue. Error concealment can replace this with a generic error.
API endpoints and SDK methods
Section titled “API endpoints and SDK methods”| Method | Endpoints | SDK |
|---|---|---|
| Discovery | GET /elevate |
getElevationMethods |
| Security key | POST /elevate/webauthn, POST /elevate/webauthn/verify |
elevateWebauthn, verifyElevateWebauthn |
| TOTP | POST /elevate/totp |
elevateTotp |
| Email OTP | POST /elevate/otp/email, POST /elevate/otp/email/verify |
elevateOTPEmail, verifyElevateOTPEmail |
| SMS OTP | POST /elevate/otp/sms, POST /elevate/otp/sms/verify |
elevateOTPSms, verifyElevateOTPSms |
All /elevate/* endpoints are subject to the brute-force rate limit. Requesting an OTP also counts against the email or SMS rate limit respectively.
Protecting your data
Section titled “Protecting your data”You can use the claim x-hasura-auth-elevated in exactly the same way you would normally use X-Hasura-User-Id for added security. For instance, the following permissions would allow users to see their data without any extra security:

While the following permissions would require them first to elevate their access in order to update them:

Protecting Auth data
Section titled “Protecting Auth data”Some user information needs to be changed via Auth’s API rather than via GraphQL mutations. These endpoints are:
- /user/password for changing passwords
- /user/email/change for changing emails
- /user/phone-number/change and /user/phone-number/change/verify for changing phone numbers
- /mfa/totp/generate for setting up TOTP
- /user/webauthn/add and /user/webauthn/verify for adding security keys
- /pat for PAT creation
- /link/idtoken for linking an identity provider account
To protect these endpoints and require the elevated claim you can use the following configuration option:
[auth.elevatedPrivileges]mode = 'required'The mode can be one of disabled (default), recommended, required.
In disabled mode the elevated claim isn’t required for any of the endpoints above. This is the default behavior. Users can still elevate their sessions, and GraphQL permissions that check x-hasura-auth-elevated still apply independently of this setting.
In recommended mode, the elevated claim is only required if the user has at least one elevation method available. Users with no available method can perform the actions above without elevating. A registered security key or activated TOTP only counts while that method is enabled for the project.
In required mode, all of the endpoints above require an access token with the elevated claim. The only exception is setting up a first factor: if the user has no elevation method available, they can register a security key (/user/webauthn/add and /user/webauthn/verify) or start TOTP setup (/mfa/totp/generate) without the elevated claim. Every other endpoint still requires it, so such a user can’t perform any other protected action until they set up a factor and elevate their session. Once the user has any method available, setting up additional factors requires the elevated claim as well.
Example
Section titled “Example”To demonstrate this functionality we have implemented them in our react-apollo (source) and vue-apollo (source) examples.
Secret Notes
Section titled “Secret Notes”To demonstrate how the elevated claim can work for permissions you can check the “Secret Notes” example. In this example, we are allowing users to see their secret notes by giving the select permissions notes.user_id eq X-Hasura-User-Id

However, we are requiring elevated permissions to insert, update and delete with the permissions notes.user_id eq x-hasura-auth-elevated. In our example we automatically initiate the elevation process if the claim isn’t already present:

Note that after elevating permissions the secret note is added and the elevated claim persists until there is a token refreshed.

Updating profile information
Section titled “Updating profile information”In addition, to demonstrate the auth.elevatedPrivileges setting, we have set it to required in this example requiring elevated access to perform certain changes. For instance, if you try to change your password you will first have to elevate your access:

After elevating access the password is changed:
