Import
You can import and use this package with:Usage
Error handling
The SDK will throw errors in most operations if the request returns a status >=300 or if the request fails entirely (i.e., due to network errors). The type of the error will be aFetchError<ErrorResponse>:
Error type so if you want to just log the error you can
do so like this:
Interfaces
AuthenticationExtensionsClientOutputs
Map of extension outputs from the clientProperties
appid?
credProps?
hmacCreateSecret?
AuthenticatorAssertionResponse
Properties
authenticatorData
string) - Base64url encoded authenticator data
clientDataJSON
string) - Base64url encoded client data JSON
signature
string) - Base64url encoded assertion signature
userHandle?
AuthenticatorAttestationResponse
Properties
attestationObject
string) - Base64url-encoded binary data
- Format - byte
 
authenticatorData?
clientDataJSON
string) - Base64url-encoded binary data
- Format - byte
 
publicKey?
publicKeyAlgorithm?
transports?
AuthenticatorSelection
Properties
authenticatorAttachment?
requireResidentKey?
residentKey?
userVerification?
Client
Properties
baseURL
Methods
addSecurityKey()
- 200: PublicKeyCredentialCreationOptions
 
Parameters
| Parameter | Type | 
|---|---|
options? | RequestInit | 
Returns
Promise<FetchResponse<PublicKeyCredentialCreationOptions>>
changeUserEmail()
- 200: OKResponse
 
Parameters
| Parameter | Type | 
|---|---|
body | UserEmailChangeRequest | 
options? | RequestInit | 
Returns
Promise<FetchResponse<"OK">>
changeUserMfa()
- 200: TotpGenerateResponse
 
Parameters
| Parameter | Type | 
|---|---|
options? | RequestInit | 
Returns
Promise<FetchResponse<TotpGenerateResponse>>
changeUserPassword()
- 200: OKResponse
 
Parameters
| Parameter | Type | 
|---|---|
body | UserPasswordRequest | 
options? | RequestInit | 
Returns
Promise<FetchResponse<"OK">>
createPAT()
- 200: CreatePATResponse
 
Parameters
| Parameter | Type | 
|---|---|
body | CreatePATRequest | 
options? | RequestInit | 
Returns
Promise<FetchResponse<CreatePATResponse>>
deanonymizeUser()
- 200: OKResponse
 
Parameters
| Parameter | Type | 
|---|---|
body | UserDeanonymizeRequest | 
options? | RequestInit | 
Returns
Promise<FetchResponse<"OK">>
elevateWebauthn()
- 200: PublicKeyCredentialRequestOptions
 
Parameters
| Parameter | Type | 
|---|---|
options? | RequestInit | 
Returns
Promise<FetchResponse<PublicKeyCredentialRequestOptions>>
getJWKs()
- 200: JWKSet
 
Parameters
| Parameter | Type | 
|---|---|
options? | RequestInit | 
Returns
Promise<FetchResponse<JWKSet>>
getProviderTokens()
- 200: ProviderSession
 
Parameters
| Parameter | Type | 
|---|---|
provider | SignInProvider | 
options? | RequestInit | 
Returns
Promise<FetchResponse<ProviderSession>>
getUser()
- 200: User
 
Parameters
| Parameter | Type | 
|---|---|
options? | RequestInit | 
Returns
Promise<FetchResponse<User>>
getVersion()
- 200: GetVersionResponse200
 
Parameters
| Parameter | Type | 
|---|---|
options? | RequestInit | 
Returns
Promise<FetchResponse<GetVersionResponse200>>
healthCheckGet()
- 200: OKResponse
 
Parameters
| Parameter | Type | 
|---|---|
options? | RequestInit | 
Returns
Promise<FetchResponse<"OK">>
healthCheckHead()
- 200: void
 
Parameters
| Parameter | Type | 
|---|---|
options? | RequestInit | 
Returns
Promise<FetchResponse<void>>
linkIdToken()
- 200: OKResponse
 
Parameters
| Parameter | Type | 
|---|---|
body | LinkIdTokenRequest | 
options? | RequestInit | 
Returns
Promise<FetchResponse<"OK">>
pushChainFunction()
Parameters
| Parameter | Type | Description | 
|---|---|---|
chainFunction | ChainFunction | The middleware function to add | 
Returns
void
refreshProviderToken()
- 200: ProviderSession
 
Parameters
| Parameter | Type | 
|---|---|
provider | SignInProvider | 
body | RefreshProviderTokenRequest | 
options? | RequestInit | 
Returns
Promise<FetchResponse<ProviderSession>>
refreshToken()
- 200: Session
 
Parameters
| Parameter | Type | 
|---|---|
body | RefreshTokenRequest | 
options? | RequestInit | 
Returns
Promise<FetchResponse<Session>>
sendPasswordResetEmail()
- 200: OKResponse
 
Parameters
| Parameter | Type | 
|---|---|
body | UserPasswordResetRequest | 
options? | RequestInit | 
Returns
Promise<FetchResponse<"OK">>
sendVerificationEmail()
- 200: OKResponse
 
Parameters
| Parameter | Type | 
|---|---|
body | UserEmailSendVerificationEmailRequest | 
options? | RequestInit | 
Returns
Promise<FetchResponse<"OK">>
signInAnonymous()
- 200: SessionPayload
 
Parameters
| Parameter | Type | 
|---|---|
body? | SignInAnonymousRequest | 
options? | RequestInit | 
Returns
Promise<FetchResponse<SessionPayload>>
signInEmailPassword()
- 200: SignInEmailPasswordResponse
 
Parameters
| Parameter | Type | 
|---|---|
body | SignInEmailPasswordRequest | 
options? | RequestInit | 
Returns
Promise<FetchResponse<SignInEmailPasswordResponse>>
signInIdToken()
- 200: SessionPayload
 
Parameters
| Parameter | Type | 
|---|---|
body | SignInIdTokenRequest | 
options? | RequestInit | 
Returns
Promise<FetchResponse<SessionPayload>>
signInOTPEmail()
- 200: OKResponse
 
Parameters
| Parameter | Type | 
|---|---|
body | SignInOTPEmailRequest | 
options? | RequestInit | 
Returns
Promise<FetchResponse<"OK">>
signInPasswordlessEmail()
- 200: OKResponse
 
Parameters
| Parameter | Type | 
|---|---|
body | SignInPasswordlessEmailRequest | 
options? | RequestInit | 
Returns
Promise<FetchResponse<"OK">>
signInPasswordlessSms()
- 200: OKResponse
 
Parameters
| Parameter | Type | 
|---|---|
body | SignInPasswordlessSmsRequest | 
options? | RequestInit | 
Returns
Promise<FetchResponse<"OK">>
signInPAT()
- 200: SessionPayload
 
Parameters
| Parameter | Type | 
|---|---|
body | SignInPATRequest | 
options? | RequestInit | 
Returns
Promise<FetchResponse<SessionPayload>>
signInProviderURL()
Parameters
| Parameter | Type | 
|---|---|
provider | SignInProvider | 
params? | SignInProviderParams | 
options? | RequestInit | 
Returns
string
signInWebauthn()
- 200: PublicKeyCredentialRequestOptions
 
Parameters
| Parameter | Type | 
|---|---|
body? | SignInWebauthnRequest | 
options? | RequestInit | 
Returns
Promise<FetchResponse<PublicKeyCredentialRequestOptions>>
signOut()
- 200: OKResponse
 
Parameters
| Parameter | Type | 
|---|---|
body | SignOutRequest | 
options? | RequestInit | 
Returns
Promise<FetchResponse<"OK">>
signUpEmailPassword()
- 200: SessionPayload
 
Parameters
| Parameter | Type | 
|---|---|
body | SignUpEmailPasswordRequest | 
options? | RequestInit | 
Returns
Promise<FetchResponse<SessionPayload>>
signUpWebauthn()
- 200: PublicKeyCredentialCreationOptions
 
Parameters
| Parameter | Type | 
|---|---|
body | SignUpWebauthnRequest | 
options? | RequestInit | 
Returns
Promise<FetchResponse<PublicKeyCredentialCreationOptions>>
verifyAddSecurityKey()
- 200: VerifyAddSecurityKeyResponse
 
Parameters
| Parameter | Type | 
|---|---|
body | VerifyAddSecurityKeyRequest | 
options? | RequestInit | 
Returns
Promise<FetchResponse<VerifyAddSecurityKeyResponse>>
verifyChangeUserMfa()
- 200: OKResponse
 
Parameters
| Parameter | Type | 
|---|---|
body | UserMfaRequest | 
options? | RequestInit | 
Returns
Promise<FetchResponse<"OK">>
verifyElevateWebauthn()
- 200: SessionPayload
 
Parameters
| Parameter | Type | 
|---|---|
body | SignInWebauthnVerifyRequest | 
options? | RequestInit | 
Returns
Promise<FetchResponse<SessionPayload>>
verifySignInMfaTotp()
- 200: SessionPayload
 
Parameters
| Parameter | Type | 
|---|---|
body | SignInMfaTotpRequest | 
options? | RequestInit | 
Returns
Promise<FetchResponse<SessionPayload>>
verifySignInOTPEmail()
- 200: SignInOTPEmailVerifyResponse
 
Parameters
| Parameter | Type | 
|---|---|
body | SignInOTPEmailVerifyRequest | 
options? | RequestInit | 
Returns
Promise<FetchResponse<SignInOTPEmailVerifyResponse>>
verifySignInPasswordlessSms()
- 200: SignInPasswordlessSmsOtpResponse
 
Parameters
| Parameter | Type | 
|---|---|
body | SignInPasswordlessSmsOtpRequest | 
options? | RequestInit | 
Returns
Promise<FetchResponse<SignInPasswordlessSmsOtpResponse>>
verifySignInWebauthn()
- 200: SessionPayload
 
Parameters
| Parameter | Type | 
|---|---|
body | SignInWebauthnVerifyRequest | 
options? | RequestInit | 
Returns
Promise<FetchResponse<SessionPayload>>
verifySignUpWebauthn()
- 200: SessionPayload
 
Parameters
| Parameter | Type | 
|---|---|
body | SignUpWebauthnVerifyRequest | 
options? | RequestInit | 
Returns
Promise<FetchResponse<SessionPayload>>
verifyTicketURL()
Parameters
| Parameter | Type | 
|---|---|
params? | VerifyTicketParams | 
options? | RequestInit | 
Returns
string
verifyToken()
- 200: string
 
Parameters
| Parameter | Type | 
|---|---|
body? | VerifyTokenRequest | 
options? | RequestInit | 
Returns
Promise<FetchResponse<string>>
CreatePATRequest
Properties
expiresAt
string) - Expiration date of the PAT
- Format - date-time
 
metadata?
{"name":"my-pat","used-by":"my-app-cli"}
CreatePATResponse
Properties
id
string) - ID of the PAT
- Example - 
"2c35b6f3-c4b9-48e3-978a-d4d0f1d42e24" - Pattern - \b[0-9a-f]\b-[0-9a-f]-[0-9a-f]-[0-9a-f]-\b[0-9a-f]\b
 
personalAccessToken
string) - PAT
- Example - 
"2c35b6f3-c4b9-48e3-978a-d4d0f1d42e24" - Pattern - \b[0-9a-f]\b-[0-9a-f]-[0-9a-f]-[0-9a-f]-\b[0-9a-f]\b
 
CredentialAssertionResponse
Properties
authenticatorAttachment?
clientExtensionResults?
id
string) - The credential’s identifier
rawId
string) - Base64url-encoded binary data
- Format - byte
 
response
AuthenticatorAssertionResponse) -
type
string) - The credential type represented by this object
CredentialCreationResponse
Properties
authenticatorAttachment?
clientExtensionResults?
id
string) - The credential’s identifier
rawId
string) - Base64url-encoded binary data
- Format - byte
 
response
AuthenticatorAttestationResponse) -
type
string) - The credential type represented by this object
CredentialParameter
Properties
alg
number) - The cryptographic algorithm identifier
type
CredentialType) - The valid credential types
CredentialPropertiesOutput
Credential properties extension outputProperties
rk?
ErrorResponse
Standardized error responseProperties
error
ErrorResponseError) - Error code identifying the specific application error
message
string) - Human-friendly error message
- Example - 
"Invalid email format" 
status
number) - HTTP status error code
- Example - 
400 
GetVersionResponse200
Properties
version
string) - The version of the authentication service
- Example - 
"1.2.3" 
JWK
JSON Web Key for JWT verificationProperties
alg
string) - Algorithm used with this key
- Example - 
"RS256" 
e
string) - RSA public exponent
- Example - 
"AQAB" 
kid
string) - Key ID
- Example - 
"key-id-1" 
kty
string) - Key type
- Example - 
"RSA" 
n
string) - RSA modulus
- Example - 
"abcd1234..." 
use
string) - Key usage
- Example - 
"sig" 
JWKSet
JSON Web Key Set for verifying JWT signaturesProperties
keys
JWK[]) - Array of public keys
LinkIdTokenRequest
Properties
idToken
string) - Apple ID token
nonce?
provider
IdTokenProvider) -
MFAChallengePayload
Challenge payload for multi-factor authenticationProperties
ticket
string) - Ticket to use when completing the MFA challenge
- Example - 
"mfaTotp:abc123def456" 
OptionsRedirectTo
Properties
redirectTo?
"https://my-app.com/catch-redirection"
Format - uri
ProviderSession
OAuth2 provider session containing access and refresh tokensProperties
accessToken
string) - OAuth2 provider access token for API calls
- Example - 
"ya29.a0AfH6SMBx..." 
expiresAt
string) - Timestamp when the access token expires
- Example - 
"2024-12-31T23:59:59Z" - Format - date-time
 
expiresIn
number) - Number of seconds until the access token expires
- Example - 
3599 
refreshToken?
"1//0gK8..."
PublicKeyCredentialCreationOptions
Properties
attestation?
attestationFormats?
authenticatorSelection?
challenge
string) - Base64url-encoded binary data
- Format - byte
 
excludeCredentials?
extensions?
hints?
pubKeyCredParams
CredentialParameter[]) - The desired credential types and their respective cryptographic parameters
rp
RelyingPartyEntity) -
timeout?
user
UserEntity) -
PublicKeyCredentialDescriptor
Properties
id
string) - Base64url-encoded binary data
- Format - byte
 
transports?
type
CredentialType) - The valid credential types
PublicKeyCredentialRequestOptions
Properties
allowCredentials?
challenge
string) - Base64url-encoded binary data
- Format - byte
 
extensions?
hints?
rpId?
timeout?
userVerification?
RefreshProviderTokenRequest
Request to refresh OAuth2 provider tokensProperties
refreshToken
string) - OAuth2 provider refresh token obtained from previous authentication
- Example - 
"1//0gK8..." 
RefreshTokenRequest
Request to refresh an access tokenProperties
refreshToken
string) - Refresh token used to generate a new access token
- Example - 
"2c35b6f3-c4b9-48e3-978a-d4d0f1d42e24" - Pattern - \b[0-9a-f]\b-[0-9a-f]-[0-9a-f]-[0-9a-f]-\b[0-9a-f]\b
 
RelyingPartyEntity
Properties
id
string) - A unique identifier for the Relying Party entity, which sets the RP ID
name
string) - A human-palatable name for the entity
Session
User authentication session containing tokens and user informationExtended by
Properties
accessToken
string) - JWT token for authenticating API requests
- Example - 
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." 
accessTokenExpiresIn
number) - Expiration time of the access token in seconds
- Example - 
900 - Format - int64
 
refreshToken
string) - Token used to refresh the access token
- Example - 
"2c35b6f3-c4b9-48e3-978a-d4d0f1d42e24" - Pattern - \b[0-9a-f]\b-[0-9a-f]-[0-9a-f]-[0-9a-f]-\b[0-9a-f]\b
 
refreshTokenId
string) - Identifier for the refresh token
- Example - 
"2c35b6f3-c4b9-48e3-978a-d4d0f1d42e24" - Pattern - \b[0-9a-f]\b-[0-9a-f]-[0-9a-f]-[0-9a-f]-\b[0-9a-f]\b
 
user?
SessionPayload
Container for session informationProperties
session?
SignInAnonymousRequest
Properties
displayName?
"John Smith"
locale?
"en"
MinLength - 2
MaxLength - 2
metadata?
{"firstName":"John","lastName":"Smith"}
SignInEmailPasswordRequest
Request to authenticate using email and passwordProperties
string) - User’s email address
- Example - 
"john.smith@nhost.io" - Format - email
 
password
string) - User’s password
- Example - 
"Str0ngPassw#ord-94|%" - MinLength - 3
 - MaxLength - 50
 
SignInEmailPasswordResponse
Response for email-password authentication that may include a session or MFA challengeProperties
mfa?
session?
SignInIdTokenRequest
Properties
idToken
string) - Apple ID token
nonce?
options?
provider
IdTokenProvider) -
SignInMfaTotpRequest
Properties
otp
string) - One time password
ticket
string) - Ticket
- Pattern - ^mfaTotp:.*$
 
SignInOTPEmailRequest
Properties
string) - A valid email
- Example - 
"john.smith@nhost.io" - Format - email
 
options?
SignInOTPEmailVerifyRequest
Properties
string) - A valid email
- Example - 
"john.smith@nhost.io" - Format - email
 
otp
string) - One time password
SignInOTPEmailVerifyResponse
Properties
session?
SignInPasswordlessEmailRequest
Properties
string) - A valid email
- Example - 
"john.smith@nhost.io" - Format - email
 
options?
SignInPasswordlessSmsOtpRequest
Properties
otp
string) - One-time password received by SMS
phoneNumber
string) - Phone number of the user
- Example - 
"+123456789" 
SignInPasswordlessSmsOtpResponse
Properties
mfa?
session?
SignInPasswordlessSmsRequest
Properties
options?
phoneNumber
string) - Phone number of the user
- Example - 
"+123456789" 
SignInPATRequest
Properties
personalAccessToken
string) - PAT
- Example - 
"2c35b6f3-c4b9-48e3-978a-d4d0f1d42e24" - Pattern - \b[0-9a-f]\b-[0-9a-f]-[0-9a-f]-[0-9a-f]-\b[0-9a-f]\b
 
SignInProviderParams
Parameters for the signInProvider method.Properties
allowedRoles?
connect?
defaultRole?
displayName?
locale?
metadata?
redirectTo?
state?
SignInWebauthnRequest
Properties
email?
"john.smith@nhost.io"
Format - email
SignInWebauthnVerifyRequest
Properties
credential
CredentialAssertionResponse) -
email?
"john.smith@nhost.io"
Format - email
SignOutRequest
Properties
all?
refreshToken?
SignUpEmailPasswordRequest
Request to register a new user with email and passwordProperties
string) - Email address for the new user account
- Example - 
"john.smith@nhost.io" - Format - email
 
options?
password
string) - Password for the new user account
- Example - 
"Str0ngPassw#ord-94|%" - MinLength - 3
 - MaxLength - 50
 
SignUpOptions
Properties
allowedRoles?
["me","user"]
defaultRole?
"user"
displayName?
"John Smith"
Pattern - ^[\p\p\p ,.’-]+$
MaxLength - 32
locale?
"en"
MinLength - 2
MaxLength - 2
metadata?
{"firstName":"John","lastName":"Smith"}
redirectTo?
"https://my-app.com/catch-redirection"
Format - uri
SignUpWebauthnRequest
Properties
string) - A valid email
- Example - 
"john.smith@nhost.io" - Format - email
 
options?
SignUpWebauthnVerifyRequest
Properties
credential
CredentialCreationResponse) -
nickname?
options?
TotpGenerateResponse
Response containing TOTP setup information for MFAProperties
imageUrl
string) - URL to QR code image for scanning with an authenticator app
- Example - 
"data:image/png;base64,iVBORw0KGg..." 
totpSecret
string) - TOTP secret key for manual setup with an authenticator app
- Example - 
"ABCDEFGHIJK23456" 
User
User profile and account informationProperties
activeMfaType?
avatarUrl
string) - URL to the user’s profile picture
- Example - 
"https://myapp.com/avatars/user123.jpg" 
createdAt
string) - Timestamp when the user account was created
- Example - 
"2023-01-15T12:34:56Z" - Format - date-time
 
defaultRole
string) - Default authorization role for the user
- Example - 
"user" 
displayName
string) - User’s display name
- Example - 
"John Smith" 
email?
"john.smith@nhost.io"
Format - email
emailVerified
boolean) - Whether the user’s email has been verified
- Example - 
true 
id
string) - Unique identifier for the user
- Example - 
"2c35b6f3-c4b9-48e3-978a-d4d0f1d42e24" - Pattern - \b[0-9a-f]\b-[0-9a-f]-[0-9a-f]-[0-9a-f]-\b[0-9a-f]\b
 
isAnonymous
boolean) - Whether this is an anonymous user account
- Example - 
false 
locale
string) - User’s preferred locale (language code)
- Example - 
"en" - MinLength - 2
 - MaxLength - 2
 
metadata
Record<string, unknown>) - Custom metadata associated with the user
- Example - 
{"firstName":"John","lastName":"Smith"} 
phoneNumber?
"+12025550123"
phoneNumberVerified
boolean) - Whether the user’s phone number has been verified
- Example - 
false 
roles
string[]) - List of roles assigned to the user
- Example - 
["user","customer"] 
UserDeanonymizeRequest
Properties
connection?
string) - A valid email
- Example - 
"john.smith@nhost.io" - Format - email
 
options?
password?
"Str0ngPassw#ord-94|%"
MinLength - 3
MaxLength - 50
signInMethod
UserDeanonymizeRequestSignInMethod) - Which sign-in method to use
UserEmailChangeRequest
Properties
newEmail
string) - A valid email
- Example - 
"john.smith@nhost.io" - Format - email
 
options?
UserEmailSendVerificationEmailRequest
Properties
string) - A valid email
- Example - 
"john.smith@nhost.io" - Format - email
 
options?
UserEntity
Properties
displayName
string) - A human-palatable name for the user account, intended only for display
id
string) - The user handle of the user account entity
name
string) - A human-palatable name for the entity
UserMfaRequest
Request to activate or deactivate multi-factor authenticationProperties
activeMfaType?
"totp"
code
string) - Verification code from the authenticator app when activating MFA
- Example - 
"123456" 
UserPasswordRequest
Properties
newPassword
string) - A password of minimum 3 characters
- Example - 
"Str0ngPassw#ord-94|%" - MinLength - 3
 - MaxLength - 50
 
ticket?
UserPasswordResetRequest
Properties
string) - A valid email
- Example - 
"john.smith@nhost.io" - Format - email
 
options?
VerifyAddSecurityKeyRequest
Properties
credential
CredentialCreationResponse) -
nickname?
VerifyAddSecurityKeyResponse
Properties
id
string) - The ID of the newly added security key
- Example - 
"123e4567-e89b-12d3-a456-426614174000" 
nickname?
VerifyTicketParams
Parameters for the verifyTicket method.Properties
redirectTo
- Target URL for the redirect
 
ticket
- Ticket
 
type?
- Type of the ticket
 
VerifyTokenRequest
Properties
token?
Type Aliases
AttestationFormat
AuthenticatorAttachment
AuthenticatorTransport
ConveyancePreference
CredentialType
ErrorResponseError
IdTokenProvider
OKResponse
PublicKeyCredentialHints
RedirectToQuery
ResidentKeyRequirement
SignInProvider
TicketQuery
TicketTypeQuery
URLEncodedBase64
UserDeanonymizeRequestSignInMethod
UserMfaRequestActiveMfaType
UserVerificationRequirement
Functions
createAPIClient()
Parameters
| Parameter | Type | Default value | 
|---|---|---|
baseURL | string | undefined | 
chainFunctions | ChainFunction[] | [] | 
Returns
Client