Local Development
Deploy AuthHero locally for development or on VPS/dedicated servers for production.
Node.js
The most common setup for local development and traditional server deployments.
Requirements
- Node.js 18+ or 20+
- A data adapter (Kysely, Drizzle, or custom)
Setup
import { serveStatic } from "@hono/node-server/serve-static";
import { serve } from "@hono/node-server";
import { initMultiTenant } from "@authhero/multi-tenancy";
import path from "path";
import { fileURLToPath } from "url";
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const { app } = initMultiTenant({
dataAdapter,
// Widget asset handler for Node.js
widgetHandler: serveStatic({
root: path.resolve(
__dirname,
"../node_modules/authhero/dist/assets/u/widget",
),
rewriteRequestPath: (p) => p.replace("/u/widget", ""),
}),
});
serve({ fetch: app.fetch, port: 3000 });Recommended Adapters
@authhero/drizzle- SQLite throughbetter-sqlite3(recommended; used by thelocaltemplate)@authhero/kysely-adapter- SQLite, or MySQL on PlanetScale, for existing deployments
Production Deployment
For production on VPS or dedicated servers:
Use a process manager (PM2, systemd)
bash# PM2 pm2 start dist/index.js --name authhero pm2 save pm2 startupSet up reverse proxy (nginx, Caddy)
nginx# nginx server { listen 80; server_name auth.example.com; location / { proxy_pass http://localhost:3000; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; } }Configure SSL (Let's Encrypt)
bashcertbot --nginx -d auth.example.com
Bun
Fast JavaScript runtime with built-in TypeScript support.
Requirements
- Bun 1.0+
- A data adapter
Setup
import { serveStatic } from "hono/bun";
import { initMultiTenant } from "@authhero/multi-tenancy";
const { app } = initMultiTenant({
dataAdapter,
// Widget asset handler for Bun
widgetHandler: serveStatic({
root: "./node_modules/authhero/dist/assets/u/widget",
rewriteRequestPath: (p) => p.replace("/u/widget", ""),
}),
});
export default {
fetch: app.fetch,
port: 3000,
};Running
bun run src/index.tsRecommended Adapters
@authhero/drizzle- SQLite throughdrizzle-orm/bun-sqlite(Bun's built-in SQLite). This combination is not covered by AuthHero's test suite.
Deno
Secure TypeScript runtime with modern APIs.
Requirements
- Deno 1.30+
- A data adapter
Setup
import { serveStatic } from "hono/deno";
import { initMultiTenant } from "@authhero/multi-tenancy";
const { app } = initMultiTenant({
dataAdapter,
widgetHandler: serveStatic({
root: "./node_modules/authhero/dist/assets/u/widget",
rewriteRequestPath: (p) => p.replace("/u/widget", ""),
}),
});
Deno.serve({ port: 3000 }, app.fetch);Running
deno run --allow-net --allow-read src/index.tsDocker
For Docker deployments, see the dedicated Docker deployment guide. The AuthHero repository includes a ready-to-use Dockerfile with SQLite, auto-migrations, and seeding built in.
Environment Variables
Common environment variables for local deployments:
# Database (SQLite file used by your server code)
DATABASE_PATH=./data/db.sqlite
# Server
PORT=3000
NODE_ENV=production
# Optional
LOG_LEVEL=info
ALLOWED_ORIGINS=https://app.example.comDevelopment Workflow
Install dependencies
bashnpm install # or pnpm install # or bun installRun database migrations
bashnpm run migrateStart development server
bashnpm run devAccess the application
- AuthHero API:
http://localhost:3000 - Widget test page:
http://localhost:3000/demo
- AuthHero API:
Troubleshooting
Widget files not loading
Ensure the widgetHandler path is correct:
// Use absolute path for Node.js
import { fileURLToPath } from "url";
const __dirname = path.dirname(fileURLToPath(import.meta.url));
widgetHandler: serveStatic({
root: path.resolve(
__dirname,
"../node_modules/authhero/dist/assets/u/widget",
),
rewriteRequestPath: (p) => p.replace("/u/widget", ""),
});Port already in use
# Find process using port 3000
lsof -i :3000
# Kill the process
kill -9 <PID>Database connection errors
Check that the SQLite file exists, is writable by the server process, and has the migrations applied:
sqlite3 ./data/db.sqlite "SELECT name FROM sqlite_master WHERE type = 'table' LIMIT 5;"