Skip to main content

AuthResponse

Package: @nauth-toolkit/client Type: Response

Unified response from authentication operations. Contains either user/tokens on successful authentication or challenge data when additional verification is required.

import { AuthResponse } from '@nauth-toolkit/client';

Properties

PropertyTypeDescription
userAuthUserSummaryUser info (present on successful auth)
accessTokenstringAccess token (JSON mode only)
refreshTokenstringRefresh token (JSON mode only)
accessTokenExpiresAtnumberAccess token expiry timestamp (milliseconds since epoch)
refreshTokenExpiresAtnumberRefresh token expiry timestamp (milliseconds since epoch)
authMethodstringAuthentication method used to create the current session (password, google, apple, facebook)
trustedbooleanWhether device is trusted
deviceTokenstringDevice trust token
challengeNameAuthChallengeChallenge type (if auth incomplete)
sessionstringChallenge session token (required for challenge responses)
challengeParametersRecord<string, unknown>Challenge-specific data (e.g., masked email/phone, available MFA methods)
substringUser subject identifier

Example

Successful Authentication

{
"user": {
"sub": "user_123",
"email": "user@example.com",
"firstName": "John",
"lastName": "Doe",
"phone": "+14155551234",
"isEmailVerified": true,
"isPhoneVerified": true,
"socialProviders": ["google"],
"hasPasswordHash": true
},
"accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"refreshToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"accessTokenExpiresAt": 1704067200000,
"refreshTokenExpiresAt": 1704153600000,
"authMethod": "password",
"trusted": true,
"deviceToken": "device_token_abc123"
}

Challenge Response

VERIFY_EMAIL Challenge

{
"challengeName": "VERIFY_EMAIL",
"session": "challenge_session_token_xyz",
"challengeParameters": {
"email": "user@example.com",
"codeDeliveryDestination": "u***r@example.com"
},
"sub": "user_123"
}

VERIFY_PHONE Challenge

{
"challengeName": "VERIFY_PHONE",
"session": "challenge_session_token_xyz",
"challengeParameters": {
"phone": "+14155551234",
"codeDeliveryDestination": "***-***-1234",
"requiresPhoneCollection": "false"
},
"sub": "user_123"
}

When phone collection is required (user has no phone number):

{
"challengeName": "VERIFY_PHONE",
"session": "challenge_session_token_xyz",
"challengeParameters": {
"requiresPhoneCollection": "true",
"instructions": "You must add a phone number and verify it to continue"
},
"sub": "user_123"
}

MFA_REQUIRED Challenge

{
"challengeName": "MFA_REQUIRED",
"session": "challenge_session_token_xyz",
"challengeParameters": {
"preferredMethod": "sms",
"maskedPhone": "***-***-9393",
"maskedEmail": "m***2@example.com",
"availableMethods": ["sms", "email", "totp", "backup"]
},
"sub": "user_123"
}

Note: For MFA_REQUIRED challenges, use getMaskedDestination() to get the correct masked destination based on preferredMethod. The helper automatically returns maskedPhone for SMS or maskedEmail for Email MFA.

Used By