@aura-stack/elysia
v0.1.0
Published
Authentication integration for Elysia applications. Provides middleware, route handlers and session verification powered by Aura Auth.
Maintainers
Readme
Elysia middleware and utilities for the Aura Stack authentication library
Official Docs · Elysia Package Docs
Overview
@aura-stack/elysia provides a seamless integration layer for Elysia applications using Aura Auth. It allows you to easily mount authentication handlers and protect your routes using type-safe context derivation.
It leverages Elysia's functional architecture to provide session management and authentication flows with first-class TypeScript support.
Features
- Elysia Native — Designed to work with Elysia's
.derive()and.resolve()patterns. - Type-safe Context — Automatically injects
sessioninto your handlers with full type inference. - Unified Handlers — Bridge Web Request/Response API handlers to Elysia effortlessly.
- Deno & Bun Ready — Optimized for high-performance runtimes.
Installation
pnpm add @aura-stack/elysia @aura-stack/authQuick Start
1. Configure Auth
Create your authentication instance. This typically goes in a shared file like lib/auth.ts.
import { createAuth } from "@aura-stack/elysia"
export const auth = createAuth({
oauth: ["github"],
// your configuration
})
export const { toHandler, withAuth } = auth2. Mount Auth Endpoints
Mount the authentication endpoints using app.all().
import { Elysia } from "elysia"
import { toHandler } from "./lib/auth"
const app = new Elysia().all("/api/auth/*", (ctx) => toHandler(ctx))3. Protect Your Routes
Use the withAuth utility with .derive() to protect routes. The session will be available in the handler's context.
import { withAuth } from "./lib/auth"
app.derive(withAuth).get("/api/protected", ({ session, error }) => {
if (!session) {
return error(401, "Unauthorized")
}
return { message: `Hello, ${session.user.name}!` }
})Documentation
Visit the official documentation website for more detailed guides and API references.
License
Licensed under the MIT License. © Aura Stack
