๐ Authentication Validator Blocks
Authentication validator blocks provide validation functions for authentication-related operations in Nodeblocks applications. These validators ensure proper authentication for protected routes and resources.
๐ฏ Overviewโ
Authentication validator blocks are designed to:
- Validate authentication tokens before route access
- Support multiple authentication methods (Bearer tokens, cookies)
- Provide reusable authentication logic for route protection
- Handle authentication errors with proper error responses
๐ Authentication Validator Typesโ
Token Validatorsโ
Validators that check and validate authentication tokens.
๐ง Available Authentication Validatorsโ
isAuthenticatedโ
Authenticates user by validating the bearer token in the request context.
Purpose: Ensures the request is authenticated before proceeding
Parameters:
- none
Returns: void - Passes through if authentication succeeds
Throws: NodeblocksError (401) with message "Invalid or missing authentication token"
Usage:
import { validators } from '@nodeblocks/backend-sdk';
const { isAuthenticated } = validators;
withRoute({
validators: [isAuthenticated()]
});
verifyAuthenticationโ
Validates authentication using a provided authenticator function.
This validator is deprecated.
Replacement: isAuthenticated.
Purpose: Ensures the request is properly authenticated before proceeding with operations
Parameters:
authenticate:Authenticator- Authentication function to validate tokenspayload:RouteHandlerPayload- Contains request context and data
Returns: void - Passes through if authentication succeeds
Throws: Any errors thrown by the authenticate function (typically NodeblocksError with a relevant message)
Usage:
import { validators } from '@nodeblocks/backend-sdk';
const { verifyAuthentication } = validators;
withRoute({
validators: [verifyAuthentication(getBearerTokenInfo)]
});
๐ Related Documentationโ
- Authentication Schema Blocks - Authentication data validation and contracts
- Authentication Handler Blocks - Authentication business logic functions
- Authentication Route Blocks - Authentication HTTP endpoint definitions
- Authentication Feature Blocks - Authentication composed features