🔐 Authentication Feature Blocks
Authentication feature blocks provide complete, pre-composed functionality for user authentication operations in Nodeblocks applications. These features combine schemas, routes, and handlers to create ready-to-use API endpoints for login, registration, email verification, and session management.
🎯 Overview
Authentication feature blocks are designed to:
- Provide complete authentication workflows for user login and registration
- Combine schemas with routes for validated authentication operations
- Include security measures and token management automatically
- Support email verification and account confirmation flows
- Handle session management and logout operations seamlessly
📋 Feature Structure
Each authentication feature follows a consistent composition pattern:
- Schema: Validates authentication input data and parameters
- Route: Provides HTTP endpoint with authentication handlers
- Composition: Combines schema and route using
compose
function
🔧 Available Authentication Features
loginWithCredentialsFeature
Provides complete login and logout functionality with credential validation.
Purpose: Handles user authentication with validated credentials and secure logout
Composition:
- Schema:
loginWithCredentialsSchema
- validates login credentials - Routes:
loginWithCredentialsRoute
- POST/auth/login
with authentication handler - Routes:
logoutRoute
- POST/auth/logout
with session termination
Usage:
import { features } from '@nodeblocks/backend-sdk';
// With database configuration
app.use('/api/auth', defService(partial(features.loginWithCredentialsFeature, [{ dataStores: db }])));
API Endpoints:
POST /api/auth/login
- User authenticationPOST /api/auth/logout
- Session termination
registerCredentialsFeature
Handles user registration with credential validation and account creation.
Purpose: Processes new user registration with data validation
Composition:
- Schema:
registerCredentialsSchema
- validates registration data - Route:
registerCredentialsRoute
- POST/auth/register
with account creation
Usage:
import { features } from '@nodeblocks/backend-sdk';
// With database configuration
app.use('/api/auth', defService(partial(features.registerCredentialsFeature, [{ dataStores: db }])));
API Endpoint: POST /api/auth/register
emailVerificationFeature
Sends verification emails to users for account confirmation.
Purpose: Handles email verification request processing
Composition:
- Schema:
sendVerificationEmailSchema
- validates optional fingerprint for device security - Route:
sendVerificationEmailRoute
- POST/auth/:identityId/send-verification-email
with email sending
Usage:
import { features } from '@nodeblocks/backend-sdk';
// With database configuration
app.use('/api', defService(partial(features.emailVerificationFeature, [{ dataStores: db }])));
API Endpoint: POST /api/auth/:identityId/send-verification-email
confirmEmailFeature
Processes email confirmation tokens to verify user accounts.
Purpose: Validates email verification tokens and confirms user accounts
Composition:
- Schema:
confirmEmailSchema
- validates verification token from email - Route:
confirmEmailRoute
- POST/auth/confirm-email
with token processing
Usage:
import { features } from '@nodeblocks/backend-sdk';
// With database configuration
app.use('/api', defService(partial(features.confirmEmailFeature, [{ dataStores: db }])));
API Endpoint: POST /api/auth/confirm-email
changeEmailFeature
Email change feature with schema validation and routing for updating user email addresses.
Purpose: Handles email change initiation with validation
Composition:
- Schema:
changeEmailSchema
- validates identityId and new email (plus internal password verification in handlers) - Route:
changeEmailRoute
- PATCH/auth/:identityId/change-email
with email update processing
Usage:
import { features } from '@nodeblocks/backend-sdk';
// With database configuration
app.use('/api', defService(partial(features.changeEmailFeature, [{ dataStores: db }])));
API Endpoint: PATCH /api/auth/:identityId/change-email
checkTokenFeature
Token validation feature with schema validation and routing for authentication checks.
Purpose: Handles token validation with target context
Composition:
- Schema:
checkTokenSchema
- validates token and optional target parameters - Route:
checkTokenRoute
- POST/auth/token/check
with token validation handler
Usage:
import { features } from '@nodeblocks/backend-sdk';
// With database configuration
app.use('/api', defService(partial(features.checkTokenFeature, [{ dataStores: db }])));
API Endpoint: POST /api/auth/token/check
confirmNewEmailFeature
Email confirmation feature with schema validation for new email address verification.
Purpose: Handles new email confirmation after email change
Composition:
- Schema:
confirmNewEmailSchema
- validates verification token for new email address - Route:
confirmNewEmailRoute
- POST/auth/confirm-new-email
with new email verification
Usage:
import { features } from '@nodeblocks/backend-sdk';
// With database configuration
app.use('/api', defService(partial(features.confirmNewEmailFeature, [{ dataStores: db }])));
API Endpoint: POST /api/auth/confirm-new-email
sendResetPasswordLinkEmailFeature
Password reset email feature with schema validation and routing for password recovery.
Purpose: Handles password reset email generation and sending
Composition:
- Schema:
sendResetPasswordLinkEmailSchema
- validates email address for password reset - Route:
sendResetPasswordLinkEmailRoute
- POST/auth/send-reset-password-link-email
with password reset email sending
Usage:
import { features } from '@nodeblocks/backend-sdk';
// With database configuration
app.use('/api', defService(partial(features.sendResetPasswordLinkEmailFeature, [{ dataStores: db }])));
API Endpoint: POST /api/auth/send-reset-password-link-email
changePasswordFeature
Change password feature with schema validation and routing for updating user passwords.
Purpose: Handles password change with current password verification and new password hashing
Composition:
- Schema:
changePasswordSchema
- validates current and new passwords - Route:
changePasswordRoute
- PATCH/auth/:identityId/change-password
with password update processing
Usage:
import { features } from '@nodeblocks/backend-sdk';
// With database configuration
app.use('/api', defService(partial(features.changePasswordFeature, [{ dataStores: db }])));
API Endpoint: PATCH /api/auth/:identityId/change-password
activateFeature
Account activation feature with schema validation and routing for activating user accounts.
Purpose: Handles account activation with email verification and identity status update
Composition:
- Schema:
activateSchema
- validates identity activation request (requires identityId) - Route:
activateRoute
- POST/auth/activate
with account activation processing
Usage:
import { features } from '@nodeblocks/backend-sdk';
// With database configuration
app.use('/api', defService(partial(features.activateFeature, [{ dataStores: db }])));
API Endpoint: POST /api/auth/activate
deactivateFeature
Deactivate account feature with schema validation and routing for deactivating user accounts.
Purpose: Handles account deactivation with identity status update and token invalidation
Composition:
- Schema:
deactivateSchema
- validates deactivation request - Route:
deactivateRoute
- POST/auth/deactivate
with account deactivation processing
Usage:
import { features } from '@nodeblocks/backend-sdk';
// With database configuration
app.use('/api', defService(partial(features.deactivateFeature, [{ dataStores: db }])));
API Endpoint: POST /api/auth/deactivate
completePasswordResetFeature
Complete password reset feature with schema validation and routing for resetting user passwords.
Purpose: Handles password reset completion with token validation and password update
Composition:
- Schema:
completePasswordResetSchema
- validates new password - Route:
completePasswordResetRoute
- POST/auth/reset-password
with password update
Usage:
import { features } from '@nodeblocks/backend-sdk';
// With database configuration
app.use('/api', defService(partial(features.completePasswordResetFeature, [{ dataStores: db }])));
API Endpoint: POST /api/auth/reset-password
refreshTokenFeature
Token refresh feature with schema validation and routing for renewing access tokens.
Purpose: Handles token refresh with token rotation and security measures
Feature Composition:
- Schema:
refreshTokenSchema
- validates refresh token in request body - Routes:
refreshTokenRoute
- POST/auth/token/refresh
Usage:
import { features } from '@nodeblocks/backend-sdk';
// With database (handlers need dataStores):
app.use('/api', defService(partial(features.refreshTokenFeature, [{ dataStores: db }])));
API Endpoint: POST /api/auth/token/refresh
deleteRefreshTokensFeature
Refresh token deletion feature with schema validation and routing for removing identity refresh tokens.
Purpose: Handles secure deletion of refresh tokens for specific identities
Feature Composition:
- Schema:
deleteRefreshTokensSchema
- validates identity ID path parameter - Routes:
deleteRefreshTokensRoute
- DELETE/auth/:identityId/refresh-tokens
with authentication and access validation
Usage:
import { features } from '@nodeblocks/backend-sdk';
// With database (handlers need dataStores):
app.use('/api', defService(partial(features.deleteRefreshTokensFeature, [{ dataStores: db }])));
API Endpoint: DELETE /api/auth/:identityId/refresh-tokens