Skip to main content
Version: 0.5.0 (Previous)

🔐 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.

Deprecated

This validator is deprecated.
Replacement: isAuthenticated.

Purpose: Ensures the request is properly authenticated before proceeding with operations

Parameters:

  • authenticate: Authenticator - Authentication function to validate tokens
  • payload: 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)]
});