@cinnabun/auth
v0.0.13
Published
Authentication and authorization module for Cinnabun
Readme
@cinnabun/auth
Authentication and authorization module for Cinnabun. JWT and session-based auth with guards and role support.
Installation
bun add @cinnabun/authQuick Start
1. Configure the module
import { CinnabunApp, CinnabunFactory } from "@cinnabun/core";
import { AuthModule, AuthPlugin } from "@cinnabun/auth";
@CinnabunApp({
port: 3000,
scanPaths: [],
imports: [
AuthModule.forRoot({
strategy: "jwt",
jwt: {
secret: process.env.JWT_SECRET ?? "your-secret",
expiresIn: "7d",
},
adapter: YourAuthAdapter, // implements AuthAdapter
}),
],
plugins: [new AuthPlugin()],
})
class App {}
CinnabunFactory.run(App);2. Protect routes with guards
import { RestController, GetMapping, PostMapping, Body } from "@cinnabun/core";
import { AuthGuard, Public, CurrentUser, AuthService } from "@cinnabun/auth";
@RestController("/api")
@UseGuard(AuthGuard)
class UserController {
constructor(private authService: AuthService) {}
@Public()
@PostMapping("/login")
async login(@Body() body: { email: string; password: string }) {
return this.authService.login(body.email, body.password);
}
@GetMapping("/me")
async me(@CurrentUser() user: UserIdentity) {
return user;
}
}3. Role-based access
import { Roles } from "@cinnabun/auth";
@RestController("/admin")
@UseGuard(AuthGuard)
@Roles("admin")
class AdminController {
@GetMapping("/")
index() {
return { message: "Admin only" };
}
}Strategies
- JWT — Stateless tokens with configurable expiry
- Session — Server-side sessions with cookie store
License
MIT
