UNPKG

@re-auth/http-adapters

Version:

HTTP protocol adapters for ReAuth - framework-agnostic integration with Express, Fastify, and Hono

84 lines (81 loc) 2.52 kB
import { AuthenticatedUser, HttpAdapterConfig, HttpRequest } from '../types.js'; import { ReAuthHttpAdapter } from '../base-adapter.js'; import { Context, Hono } from 'hono'; import { LoggerInterface } from '@re-auth/logger'; import '@re-auth/reauth'; import '@re-auth/reauth/services'; import 'hono/utils/cookie'; declare class HonoAdapter { readonly name = "hono"; private adapter; private generateDeviceInfo?; constructor(config: HttpAdapterConfig, generateDeviceInfo?: (request: Context) => Promise<Record<string, any>>, logger?: LoggerInterface); /** * Generate device info from request */ generateDeviceInfoInternal(request: Context): Promise<Record<string, any>>; /** * Create Hono user middleware that populates c.get('user') */ createUserMiddleware(): (c: Context, next: any) => Promise<void>; /** * Get current user from Hono context */ getCurrentUser(c: Context): Promise<AuthenticatedUser | null>; /** * Extract HTTP request from Hono context */ extractRequest(c: Context): HttpRequest; /** * Send response using Hono context */ sendResponse(c: any, data: any, statusCode?: number): void; /** * Handle error using Hono context */ handleError(c: Context, error: Error, statusCode?: number): void; /** * Register routes on existing Hono app */ registerRoutes(app: Hono, basePath?: string, exposeIntrospection?: boolean): void; /** * Create step execution handler */ private createStepHandler; private createSessionCheckHandler; /** * Create plugin list handler */ private createPluginListHandler; /** * Create plugin details handler */ private createPluginDetailsHandler; /** * Create introspection handler */ private createIntrospectionHandler; /** * Create health check handler */ private createHealthHandler; /** * Handle error response */ private handleErrorResponse; /** * Get the base adapter instance */ getAdapter(): ReAuthHttpAdapter; } /** * Hono middleware factory function */ declare function honoReAuth(config: HttpAdapterConfig, generateDeviceInfo?: (request: Context) => Promise<Record<string, any>>, logger?: LoggerInterface): HonoAdapter; declare module 'hono' { interface ContextVariableMap { user?: AuthenticatedUser | null; authenticated: boolean; } } export { HonoAdapter, honoReAuth };