bohoauth
Simple password protection for your Next.js application.
Boho auth provides a simple way to password protect pages in your Next.js application. It has only one dependency, jose.
Installation
npm install bohoauthUsage
Create a
boho.tsfile in thelibfolder of your Next.js application:import { bohoAuth } from "bohoauth"; export const boho = bohoAuth({ password: process.env.BOHO_PASSWORD!, secret: process.env.BOHO_SECRET!, expiresIn: "1h", middleware: { loginPath: "/login", protectedPaths: ["/protected"], redirectPath: "/protected", }, });Create a route handler
app/api/login/route.ts:import { boho } from "@/lib/boho"; export const { POST } = boho.handlers;Add the middleware to your Next.js application:
import { boho } from "@/lib/boho"; export default boho.middleware;Finally, add a form to your login page that will submit to the
/api/loginroute.
Configuration Options
password: The password to use for authentication. UsesBOHO_PASSWORDenv variable if not provided.secret: The secret for JWT signing. UsesBOHO_SECRETenv variable if not provided.expiresIn: Token expiration time. Defaults to "1h".middleware.loginPath: Path to redirect unauthenticated users.middleware.protectedPaths: Array of paths to protect.middleware.redirectPath: Path to redirect after successful login.
Contributing
Contributions are welcome! Please open an issue or submit a pull request.