🔐 Authentication Blocks
Authentication blocks provide comprehensive functionality for user authentication and authorization in Nodeblocks applications. These blocks handle authentication flows including OAuth, email/password, email verification, multi-factor authentication (MFA), one-time tokens, and session management.
🎯 Overview
Authentication blocks are designed to:
- Support multiple authentication methods (OAuth, email/password, one-time tokens)
- Handle email verification and confirmation workflows
- Manage user sessions and security tokens
- Provide secure authentication with device fingerprinting
- Enable flexible registration with various validation options
- Support multi-factor authentication (MFA) with code generation and verification
📦 Block Types
🔍 Schemas
JSON Schema definitions for authentication data validation:
- providerSchema: OAuth provider authentication
- credentialsSchema: Email/password authentication
- identitySchema: Flexible authentication with multiple methods
- loginWithCredentialsSchema: Login validation with fingerprinting
- resendMfaCodeSchema: MFA code resend validation
- verifyMfaCodeSchema: MFA code verification validation
- registerCredentialsSchema: User registration validation
- sendVerificationEmailSchema: Email verification requests
- confirmEmailSchema: Email confirmation with tokens
- changeEmailSchema: Email change validation
- checkTokenSchema: Token validation with target context
- confirmNewEmailSchema: New email confirmation validation
- sendResetPasswordLinkEmailSchema: Password reset email validation
- passwordSchema: Password field validation (length/pattern)
- changePasswordSchema: Change password validation
- completePasswordResetSchema: Reset password completion validation
- activateSchema: Account activation validation
- deactivateSchema: Account deactivation validation
- loginWithOnetimeTokenSchema: One-time token login validation
- refreshTokenSchema: Refresh token validation
- deleteRefreshTokensSchema: Refresh token deletion validation
⚙️ Handlers
Core business logic for authentication operations:
- loginWithCredentials: User authentication with credentials
- createAccessToken: Access token generation
- createRefreshToken: Refresh token generation
- setResponseCookie: Sets auth cookies in response
- logout: Session termination and cleanup
- registerCredentials: User account creation
- sendVerificationEmail: Email verification sending
- confirmEmail: Email confirmation processing
- buildCheckConfirmEmailTokenPayload: Prepares check token payload for confirm-email
- checkToken: Token validation processing
- refreshToken: Access token refresh using refresh token with enhanced security
- deleteToken: Token deletion (admin)
- loginWithOnetimeToken: Authenticate with OTT
- generateOnetimeToken: Generate OTT (admin)
- restoreOnetimeToken: Restore OTT (admin)
- invalidateOnetimeToken: Invalidate OTT (admin)
- loginTerminator: Formats login response
- logoutTerminator: Formats logout response
- registerTerminator: Formats registration response
- confirmEmailTerminator: Formats email confirmation response
- sendVerificationEmailTerminator: Formats verification email response
View Authentication Handlers →
🛣️ Routes
HTTP endpoint definitions for authentication operations:
- loginWithCredentialsRoute: POST
/auth/loginwith authentication handler - resendMfaCodeRoute: POST
/auth/mfa/resendwith MFA code regeneration - verifyMfaCodeRoute: POST
/auth/mfa/verifywith MFA code verification - logoutRoute: POST
/auth/logoutwith session termination - refreshTokenRoute: POST
/auth/token/refreshwith access token refresh - registerCredentialsRoute: POST
/auth/registerwith account creation - sendVerificationEmailRoute: POST
/auth/:identityId/send-verification-emailwith email sending - confirmEmailRoute: POST
/auth/confirm-emailwith token processing - changeEmailRoute: PATCH
/auth/:identityId/change-emailwith email update processing - checkTokenRoute: POST
/auth/token/checkwith token validation handler - deleteRefreshTokensRoute: DELETE
/auth/:identityId/refresh-tokenswith authentication and access validation - loginWithOnetimeTokenRoute: POST
/auth/ott/loginwith OTT authentication - generateOnetimeTokenRoute: POST
/auth/ott/generatewith OTT generation (admin) - restoreOnetimeTokenRoute: POST
/auth/ott/restorewith OTT restore (admin) - invalidateOnetimeTokenRoute: POST
/auth/ott/invalidatewith OTT invalidation (admin) - confirmNewEmailRoute: POST
/auth/confirm-new-emailwith new email verification - sendResetPasswordLinkEmailRoute: POST
/auth/send-reset-password-link-emailwith password reset email sending - changePasswordRoute: PATCH
/auth/:identityId/change-passwordwith password update processing - activateRoute: POST
/auth/activatewith account activation processing - deactivateRoute: POST
/auth/deactivatewith account deactivation processing - completePasswordResetRoute: POST
/auth/reset-passwordwith password update
🚀 Features
Complete authentication management features combining schemas, routes, and handlers:
- loginWithCredentialsFeature: User authentication with validated credentials and secure logout
- verifyMfaCodeFeature: Multi-factor authentication code verification workflow
- resendMfaCodeFeature: MFA code regeneration for users needing new verification codes
- loginWithOnetimeTokenFeature: Passwordless authentication using one-time tokens
- registerCredentialsFeature: User registration with credential validation and account creation
- emailVerificationFeature: Email verification request processing with device security
- confirmEmailFeature: Email confirmation token validation and account verification
- changeEmailFeature: Email change initiation with validation
- checkTokenFeature: Token validation with target context
- confirmNewEmailFeature: New email confirmation after email change
- sendResetPasswordLinkEmailFeature: Password reset email generation and sending
- changePasswordFeature: Password change with validation and hashing
- activateFeature: Account activation workflow
- deactivateFeature: Account deactivation workflow
- completePasswordResetFeature: Password reset completion workflow
- refreshTokenFeature: Token refresh feature with schema validation and routing for renewing access tokens
- deleteRefreshTokensFeature: Refresh token deletion feature with schema validation and routing for removing identity refresh tokens
View Authentication Features →
✅ Validators
Validation functions for authentication operations:
- isAuthenticated: Validates authentication using configured authenticator
- verifyAuthentication: Validates authentication using provided authenticator function (deprecated)
View Authentication Validators →
🔧 Blocks
Pure business logic functions for authentication operations:
- Identity Management: User validation and email operations
- Token Management: Secure token lifecycle management
- Email Authentication: Verification and communication functionality
- Security Validation: Fingerprint tracking and request validation
- Multi-Factor Authentication (MFA): MFA code generation, verification, and error handling
- MFA Error Classes: Specialized error handling for MFA operations
- MFA Constants: Configuration constants for MFA functionality
🔗 Related Documentation
- Authentication Schemas - Authentication data validation and contracts
- Authentication Handlers - Business logic and authentication operations
- Authentication Routes - HTTP endpoint definitions
- Authentication Features - Complete authentication management features
- Authentication Validators - Authentication validation functions
- Invitation Blocks - Related invitation management functionality