astro()
#
Middleware for Astro 1.x, 2.x, and 3.x.
const astro: Middleware;
Usage#
auth.handleRequest(context as APIContext);
import { astro } from "lucia/middleware";
const auth = lucia({
middleware: astro()
// ...
});
elysia()
#
Middleware for Elysia.
const elysia: Middleware;
Usage#
auth.handleRequest(context as Context);
new Elysia().get("/", (context) => {
auth.handleRequest(context);
});
express()
#
Middleware for Express 4.x and 5.x.
const express: () => Middleware;
Usage#
import { express } from "lucia/middleware";
const auth = lucia({
middleware: express()
// ...
});
auth.handleRequest(request as Request, response as Response);
fastify()
#
Middleware for Fastify.
const fastify = () => Middleware;
Usage#
import { fastify } from "lucia/middleware";
const auth = lucia({
middleware: fastify()
// ...
});
auth.handleRequest(request as FastifyRequest, reply as FastifyReply);
h3()
#
Middleware for H3 (Nuxt 3).
const h3: () => Middleware;
Usage#
import { h3 } from "lucia/middleware";
const auth = lucia({
middleware: h3()
// ...
});
auth.handleRequest(event as H3Event);
hono()
#
Middleware for Hono.
const hono: Middleware;
Usage#
auth.handleRequest(context as Context);
app.get("/", (context) => {
auth.handleRequest(context);
});
lucia()
#
The default middleware.
const lucia: () => Middleware;
Usage#
import { lucia as luciaMiddleware } from "lucia/middleware";
const auth = lucia({
middleware: luciaMiddleware()
// ...
});
auth.handleRequest(requestContext as RequestContext);
nextjs()
#
While this is not deprecated, it will be replaced with nextjs_future()
in the next major release.
Middleware for Next.js v12 and v13 - supports both pages
and app
directory. AuthRequest.setSession()
is disabled when:
- Just
NextRequest
is passed
- Used inside
getServerSideProps()
in Edge runtime
const nextjs: () => Middleware;
Usage#
import { nextjs } from "lucia/middleware";
const auth = lucia({
middleware: nextjs()
// ...
});
auth.handleRequest({
req: req as IncomingMessage,
res: res as OutgoingMessage | undefined
});
auth.handleRequest({
request: request as NextRequest | null,
cookies: cookies as Cookies
});
// for middleware and API routes in edge runtime
const authRequest = auth.handleRequest(request as NextRequest);
authRequest.setSession(); // error!
name | type | description |
---|
request | NextRequest | null | Should be provided when using API routes |
cookies | Cookies | |
nextjs_future()
#
A newer version of nextjs()
middleware for Lucia v3. We recommend using this middleware for future proofing your codebase.
Middleware for Next.js v12 and v13 - supports both pages
and app
directory. AuthRequest.setSession()
is disabled when:
- Just
NextRequest
is passed
- Used inside
getServerSideProps()
in Edge runtime
const nextjs_future: () => Middleware;
Usage#
import { nextjs } from "lucia/middleware";
const auth = lucia({
middleware: nextjs()
// ...
});
auth.handleRequest({
req: req as IncomingMessage,
res: res as OutgoingMessage | undefined
});
auth.handleRequest(requestMethod as string, {
cookies: cookies as Cookies,
headers: headers as Headers
});
// for middleware and API routes in edge runtime
const authRequest = auth.handleRequest(req as IncomingMessage);
const authRequest = auth.handleRequest(request as NextRequest);
authRequest.setSession(); // error!
name | type | description |
---|
requestMethod | string | Can be upper or lower case |
context.cookies | Cookies | |
context.headers | Headers | |
node()
#
Middleware for Node.js.
const node = () => Middleware;
Usage#
import { node } from "lucia/middleware";
const auth = lucia({
middleware: node()
// ...
});
auth.handleRequest(request as IncomingMessage, response as OutgoingMessage);
sveltekit()
#
Middleware for SvelteKit 1.x.
const sveltekit: () => Middleware;
Usage#
import { sveltekit } from "lucia/middleware";
const auth = lucia({
middleware: sveltekit()
// ...
});
auth.handleRequest(event as RequestEvent);
web()
#
Middleware for web standard request. AuthRequest.setSession()
is disabled when using the web()
middleware.
const web: () => Middleware;
Usage#
import { web } from "lucia/middleware";
const auth = lucia({
middleware: web()
// ...
});
const authRequest = auth.handleRequest(request as Request);
authRequest.setSession(); // error!
qwik()
#
Middleware for Qwik City.
const qwik: () => Middleware;
Usage#
import { qwik } from "lucia/middleware";
const auth = lucia({
middleware: qwik()
// ...
});
auth.handleRequest(requestEvent as RequestEventLoader);
auth.handleRequest(requestEvent as RequestEventAction);
elysia()
#
Middleware for Elysia.
const elysia: () => Middleware;
Usage#
import { elysia } from "lucia/middleware";
const auth = lucia({
middleware: elysia()
// ...
});
auth.handleRequest(context as Context);