AuthResponseDTO
Package: @nauth-toolkit/core
Type: DTO (Response)
Unified response DTO for all authentication operations. Returns tokens when successful or challenge information when verification is required.
- NestJS
- Express
- Fastify
import { AuthResponseDTO } from '@nauth-toolkit/nestjs';
import { AuthResponseDTO } from '@nauth-toolkit/core';
import { AuthResponseDTO } from '@nauth-toolkit/core';
Properties
| Property | Type | Required | Description |
|---|---|---|---|
accessToken | string | Conditional | JWT access token. Present when authentication complete. |
refreshToken | string | Conditional | JWT refresh token. Present when authentication complete. |
accessTokenExpiresAt | number | Conditional | Access token expiration (Unix timestamp). Present when tokens available. |
refreshTokenExpiresAt | number | Conditional | Refresh token expiration (Unix timestamp). Present when tokens available. |
authMethod | string | Conditional | Authentication method used to create the current session (e.g., password, google, apple, facebook). Present when authentication complete. |
trusted | boolean | Conditional | Whether device is trusted. Present when authentication complete. |
deviceToken | string | Conditional | Device trust token (UUID v4). Present when device trusted. |
user | AuthResponseUser | Conditional | User information. Present when authentication complete. |
challengeName | AuthChallenge | Conditional | Challenge type. Present when challenge required. |
session | string | Conditional | Challenge session token (UUID v4). Present when challenge required. |
challengeParameters | Record<string, unknown> | Conditional | Challenge-specific parameters. Present when challenge required. |
sub | string | Conditional | User identifier (UUID v4). Present in both success and challenge responses. |
Example
Successful Authentication:
{
"accessToken": "eyJhbGc...",
"refreshToken": "eyJhbGc...",
"accessTokenExpiresAt": 1730000000,
"refreshTokenExpiresAt": 1732592000,
"authMethod": "google",
"trusted": true,
"deviceToken": "a21b654c-2746-4168-acee-c175083a65cd",
"user": {
"sub": "b32c765d-3857-5279-bdff-d286194b76de",
"email": "user@example.com",
"firstName": "John",
"lastName": "Doe",
"phone": "+14155551234",
"isEmailVerified": true,
"isPhoneVerified": true,
"socialProviders": ["google"],
"hasPasswordHash": true
}
}
Challenge Required:
{
"challengeName": "VERIFY_EMAIL",
"session": "a21b654c-2746-4168-acee-c175083a65cd",
"challengeParameters": {
"email": "user@example.com",
"codeDeliveryDestination": "u***@example.com"
},
"sub": "b32c765d-3857-5279-bdff-d286194b76de"
}
Related Types
AuthResponseUser- User property interfaceTokenResponse- Token refresh response interfacetoAuthResponseUser()- Conversion utility function
Used By
TokenResponse
Interface returned by token refresh operations. Contains new access and refresh tokens with expiration timestamps.
import { TokenResponse } from '@nauth-toolkit/core';
| Property | Type | Description |
|---|---|---|
accessToken | string | New JWT access token |
refreshToken | string | New JWT refresh token |
accessTokenExpiresAt | number | Access token expiration (Unix timestamp) |
refreshTokenExpiresAt | number | Refresh token expiration (Unix timestamp) |
Example:
{
"accessToken": "eyJhbGc...",
"refreshToken": "eyJhbGc...",
"accessTokenExpiresAt": 1730000900,
"refreshTokenExpiresAt": 1732592900
}
Used By: AuthService.refreshToken()
toAuthResponseUser()
Utility function to convert IUser entity to AuthResponseUser interface.
function toAuthResponseUser(user: IUser): AuthResponseUser
Parameters
user-IUserentity from database
Returns
AuthResponseUser- Sanitized user object
Example
import { toAuthResponseUser, IUser } from '@nauth-toolkit/core';
const user: IUser = await userRepository.findOne({ where: { sub } });
const responseUser = toAuthResponseUser(user);