Skip to main content

IPreSignupHookProvider

Hook interface for executing validation before user creation.

Overview

The IPreSignupHookProvider interface enables validation and blocking of signups before user creation. This is the only blocking hook - it can throw exceptions to prevent signup.

The hook is blocking - throwing an exception prevents user creation.

Interface

interface IPreSignupHookProvider {
execute(
data: PreSignupHookData,
signupType: 'password' | 'social',
provider?: string,
adminSignup?: boolean,
): Promise<void>;
}

Parameters

ParameterTypeDescription
dataPreSignupHookDataSignup DTO or OAuth profile
signupType'password' | 'social'Type of signup
providerstringSocial provider name (social signups only)
adminSignupbooleanWhether admin-initiated signup

When Hook Fires

  • Before password signup via signup()
  • Before social signup (web redirect or native mobile flows)
  • Before admin signup via adminSignup() or adminSignupSocial()

Blocking Signup

Throw NAuthException with AuthErrorCode.PRESIGNUP_FAILED:

throw new NAuthException(AuthErrorCode.PRESIGNUP_FAILED, 'Email domain not allowed');

Example

import { IPreSignupHookProvider, NAuthException, AuthErrorCode } from '@nauth-toolkit/core';

export class DomainValidationHook implements IPreSignupHookProvider {
async execute(data, signupType) {
const domain = data.email?.split('@')[1];
const allowedDomains = ['company.com'];

if (domain && !allowedDomains.includes(domain)) {
throw new NAuthException(AuthErrorCode.PRESIGNUP_FAILED, 'Domain not allowed');
}
}
}