Skip to main content

NAuthRedirectsConfig

Package: @nauth-toolkit/client Type: Interface

Configuration interface for redirect URLs and challenge routing. Provides platform-agnostic routing configuration for all authentication flows (login, signup, social OAuth, and challenges).

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

Properties

PropertyTypeRequiredDefaultDescription
loginSuccessstring | nullNo'/'URL to redirect after successful login/social (no challenge). Set null to disable auto-navigation.
signupSuccessstring | nullNoundefinedURL to redirect after successful signup (no challenge). Set null to disable auto-navigation.
successstring | nullNoundefinedLegacy alias for loginSuccess. Deprecated. Set null to disable auto-navigation.
sessionExpiredstring | nullNo'/login'URL to redirect when session expires (refresh fails with 401). Set null to disable auto-navigation.
oauthErrorstring | nullNo'/login'URL to redirect when OAuth authentication fails. Set null to disable auto-navigation.
challengeBasestringNo'/auth/challenge'Base URL for challenge routes. Challenge type appended by default
challengeRoutesPartial<Record<[AuthChallenge](./auth-challenge), string>>NoundefinedCustom route mapping for each challenge type. Overrides default route construction. See AuthChallenge enum for all challenge types.
useSingleChallengeRoutebooleanNofalseWhen true, uses query param mode: /auth/challenge?challenge=VERIFY_EMAIL. When false, uses separate routes: /auth/challenge/verify-email
mfaRoutesMfaRoutesConfigNoundefinedMFA-specific route overrides (only applies to MFA_REQUIRED challenge). See below.

MfaRoutesConfig

Fine-grained control over MFA navigation. Only applies when challenge type is MFA_REQUIRED. The SDK selects routes based on the MFA method and available options:

PropertyTypeRequiredDescription
passkeystringNoRoute for passkey verification. Used when preferredMethod is 'passkey'
selectorstringNoRoute for MFA method selector. Used when multiple availableMethods exist and no preferredMethod is set
defaultstringNoRoute for other MFA methods. Used for SMS, email, and TOTP (MFAMethod values: 'sms', 'email', 'totp')

Route Building Priority

The SDK builds challenge URLs in this order (highest to lowest priority):

  1. challengeRoutes - Custom route mapping (overrides everything)
  2. useSingleChallengeRoute - Query param mode (/auth/challenge?challenge=VERIFY_EMAIL)
  3. mfaRoutes - MFA-specific routes (only for MFA_REQUIRED challenge)
  4. Default separate routes - Kebab-case routes based on challenge type

Example

import { NAuthRedirectsConfig, AuthChallenge } from '@nauth-toolkit/client';

const redirects: NAuthRedirectsConfig = {
loginSuccess: '/dashboard',
signupSuccess: '/onboarding',
sessionExpired: '/login?expired=true',
oauthError: '/login?error=oauth',
challengeBase: '/auth/challenge',

// Custom routes for specific challenges
challengeRoutes: {
[AuthChallenge.VERIFY_EMAIL]: '/verify-email',
[AuthChallenge.MFA_REQUIRED]: '/auth/two-factor',
},

// MFA-specific routes (only for MFA_REQUIRED)
mfaRoutes: {
passkey: '/auth/passkey',
selector: '/auth/choose-method',
default: '/auth/verify-code',
},

// Use query param mode instead of separate routes
useSingleChallengeRoute: false,
};

Usage in NAuthClientConfig

This interface is used as the type for the redirects property in NAuthClientConfig:

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

const config: NAuthClientConfig = {
baseUrl: 'https://api.example.com/auth',
tokenDelivery: 'cookies',
redirects: {
loginSuccess: '/dashboard',
challengeBase: '/auth/challenge',
},
};

See Also