Skip to main content

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.

import { AuthResponseDTO } from '@nauth-toolkit/nestjs';

Properties

PropertyTypeRequiredDescription
accessTokenstringConditionalJWT access token. Present when authentication complete.
refreshTokenstringConditionalJWT refresh token. Present when authentication complete.
accessTokenExpiresAtnumberConditionalAccess token expiration (Unix timestamp). Present when tokens available.
refreshTokenExpiresAtnumberConditionalRefresh token expiration (Unix timestamp). Present when tokens available.
authMethodstringConditionalAuthentication method used to create the current session (e.g., password, google, apple, facebook). Present when authentication complete.
trustedbooleanConditionalWhether device is trusted. Present when authentication complete.
deviceTokenstringConditionalDevice trust token (UUID v4). Present when device trusted.
userAuthResponseUserConditionalUser information. Present when authentication complete.
challengeNameAuthChallengeConditionalChallenge type. Present when challenge required.
sessionstringConditionalChallenge session token (UUID v4). Present when challenge required.
challengeParametersRecord<string, unknown>ConditionalChallenge-specific parameters. Present when challenge required.
substringConditionalUser 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"
}

Used By


TokenResponse

Interface returned by token refresh operations. Contains new access and refresh tokens with expiration timestamps.

import { TokenResponse } from '@nauth-toolkit/core';
PropertyTypeDescription
accessTokenstringNew JWT access token
refreshTokenstringNew JWT refresh token
accessTokenExpiresAtnumberAccess token expiration (Unix timestamp)
refreshTokenExpiresAtnumberRefresh 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 - IUser entity from database

Returns

Example

import { toAuthResponseUser, IUser } from '@nauth-toolkit/core';

const user: IUser = await userRepository.findOne({ where: { sub } });
const responseUser = toAuthResponseUser(user);