Core Services
Platform-agnostic services that power nauth-toolkit. These services work with any Node.js framework.
- NestJS
- Express
- Fastify
import { AuthService } from '@nauth-toolkit/nestjs';
import { AuthService } from '@nauth-toolkit/core';
// Access via nauth.authService after NAuth.create()
import { AuthService } from '@nauth-toolkit/core';
// Access via nauth.authService after NAuth.create()
Authentication Core
| Service | Description |
|---|---|
| AuthService | Main authentication orchestration - signup, login, password management |
Audit & Logging
| Service | Description |
|---|---|
| AuthAuditService | Audit trail logging for authentication and security events |
Client Information & Security
| Service | Description |
|---|---|
| ClientInfoService | Extract IP address, user-agent, and session context |
| CsrfService | CSRF token generation and validation |
| GeoLocationService | IP geolocation using MaxMind GeoIP2 (optional, requires configuration) |
Multi-Factor Authentication
| Service | Description |
|---|---|
| MFAService | MFA provider registry and orchestration |
Social Authentication
| Service | Description |
|---|---|
| SocialAuthService | Complete API for OAuth authentication, account linking, and management |
Verification Services
| Service | Description |
|---|---|
| EmailVerificationService | Email verification code generation and validation |
| PhoneVerificationService | Phone/SMS verification code generation and validation |
Usage Pattern
All services are injected and configured automatically by the framework adapter:
- NestJS
- Express
- Fastify
import { Injectable } from '@nestjs/common';
import { AuthService } from '@nauth-toolkit/nestjs';
@Injectable()
export class MyService {
constructor(private readonly authService: AuthService) {}
async example() {
const result = await this.authService.signup({
email: 'user@example.com',
password: 'SecurePassword123!',
});
}
}
import { NAuth, ExpressAdapter } from '@nauth-toolkit/core';
const nauth = await NAuth.create({
config: authConfig,
dataSource,
adapter: new ExpressAdapter(),
});
// Access services from nauth instance
const result = await nauth.authService.signup({
email: 'user@example.com',
password: 'SecurePassword123!',
});
import { NAuth, FastifyAdapter } from '@nauth-toolkit/core';
const nauth = await NAuth.create({
config: authConfig,
dataSource,
adapter: new FastifyAdapter(),
});
// Access services from nauth instance (wrap handlers with nauth.adapter.wrapRouteHandler)
fastify.post(
'/signup',
{ preHandler: nauth.helpers.public() },
nauth.adapter.wrapRouteHandler(async (req) => {
return nauth.authService.signup(req.body);
}),
);
Related Documentation
- Configuration - Configure services
- DTOs - Data transfer objects
- Challenge System - Understanding challenge flows