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 Auth.js with native MoroJS integration.
auth() Middleware
The main authentication middleware that integrates Auth.js 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 Auth.js Adapter
createAuthMiddleware()
Native Auth.js adapter with zero external dependencies. Direct integration with Auth.js 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 Auth.js routes when the auth middleware is installed: