Authentication API
Complete API reference for MoroJS authentication middleware, helpers, and utilities.
Authentication API Reference
Complete reference for all authentication middleware, helpers, and utilities available in MoroJS. Built on Better Auth with native MoroJS integration.
auth() Middleware
The main authentication middleware that integrates Better Auth with MoroJS. Handles OAuth flows, session management, and request enhancement.
Route Protection Middleware
requireAuth()
Basic authentication requirement with optional custom authorization
requireRole()
Role-based access control with support for multiple roles
requireAdmin()
Shorthand for admin role requirement
requirePermission()
Fine-grained permission-based access control
Authentication Utilities
Manual Authentication Checks
Use authUtils for manual authentication checks and authResponses for standardized response patterns.
Native Better Auth Adapter
createAuthMiddleware()
Native Better Auth adapter with zero external dependencies. Direct integration with Better Auth core without Express compatibility layers.
Authentication Request Object
req.auth Object
The authentication middleware automatically adds an auth object to all requests with user information and helper methods.
Authentication Routes
MoroJS automatically handles these Better Auth routes when the auth middleware is installed: