@kshitijashitole/auth-server
v1.1.0
Published
Express API server with Prisma auth, analytics, and related routes — mount in your host app or run standalone.
Downloads
203
Maintainers
Readme
@kshitijashitole/auth-server
Express + Prisma API from this monorepo’s backend app: /auth, /analytics, /secure-auth.
Install
npm install @kshitijashitole/auth-serverRequires PostgreSQL. Copy .env with DATABASE_URL next to prisma.config.ts (project / package root), then generate the client:
npm run db:generate(postinstall does not run prisma generate, so installs work without a database URL; CI and first-time setup should run db:generate explicitly.)
Environment
DATABASE_URL— PostgreSQL connection stringJWT_ACCESS_SECRETorJWT_SECRET— access tokensJWT_REFRESH_SECRET— if your token helpers expect it (seesrc/utils/generateToken.js)SMTP_*/SMTP_USER/SMTP_PASS— for OTP emailFRONTEND_URL/CORS_ORIGINS— browser clients- Admin analytics lists (recommended for production):
FAST_AUTH_ADMIN_SECRET— sendx-admin-token: <secret>(orAuthorization: Bearer <secret>) forGET /analytics/auth/eventsandGET /analytics/auth/usersFAST_AUTH_ADMIN_EMAILS— comma-separated emails allowed to call those endpoints with a normal user JWT
Use in your own Express app
import express from "express";
import authServerApp from "@kshitijashitole/auth-server";
const app = express();
app.use("/api", authServerApp); // APIs live under /api/auth, /api/analytics, …
app.listen(3000);Paths are absolute on the mounted app (/auth, not /api/auth), so mount at / or use a gateway that strips the prefix — Express sub-app mounting may still expose routes at /auth relative to the child app. Test with app.use(authServerApp) at root or adjust your reverse proxy.
Run standalone
From the package root (after DATABASE_URL is set):
npm startChecklist (local or production)
.envwithDATABASE_URL(see.env.example).npm installthennpm run db:generate.- Apply schema:
npx prisma migrate deploy(ordb:migratein dev). - Set JWT, SMTP, CORS, and optionally
FAST_AUTH_ADMIN_SECRET/FAST_AUTH_ADMIN_EMAILS. npm startor mount the exported app in your host.
Publishing (maintainers)
Canonical code lives in ../backend. From this folder:
npm install
npm run db:generate # needs DATABASE_URL in .env
npm publish --access publicprepublishOnly runs sync from ../backend then prisma generate. Ensure backend is a sibling of auth-server.
