Auth
Add user auth in one command
Auth
Add email/password auth with Better Auth, session support, and a protected me endpoint.
Installation
npx zuro-cli add authpnpm dlx zuro-cli add authbun x zuro-cli add authSmart Dependencies
Running add auth also installs missing required modules:
coredatabase(you pick PostgreSQL or MySQL if needed)error-handler
What Gets Added
auth.ts
auth.routes.ts
user.routes.ts
user.controller.ts
auth.ts
app.ts
env.ts
.env
App Wiring
CLI auto-injects routes into app.ts:
app.use(authRoutes);
app.use("/api/users", userRoutes);Environment Variables
Auth adds:
BETTER_AUTH_SECRETBETTER_AUTH_URL
Behavior:
- if
BETTER_AUTH_SECRETis missing, Zuro generates a secure random secret - if it already exists, Zuro keeps your existing value
BETTER_AUTH_URLdefaults tohttp://localhost:3000(update for your real API origin)
Database Dialect Support
Auth schema generation follows your database module:
- PostgreSQL project -> PostgreSQL auth schema
- MySQL project -> MySQL auth schema
So you can use add auth safely on either dialect.
Endpoints You Get
| Path | Method | Purpose |
|---|---|---|
/auth/sign-up/email | POST | Register |
/auth/sign-in/email | POST | Login |
/auth/sign-out | POST | Logout |
/auth/session | GET | Current session |
/api/users/me | GET | Current user profile |
First-Time Setup
- Add auth:
npx zuro-cli add auth - Run migrations:
npx drizzle-kit generate npx drizzle-kit migrate - Start server:
npm run dev
Basic Usage Example
curl -X POST http://localhost:3000/auth/sign-up/email \
-H "Content-Type: application/json" \
-d '{
"name": "Briyan",
"email": "briyan@example.com",
"password": "password123"
}'curl http://localhost:3000/api/users/me \
-H "Cookie: <session_cookie_here>"Controller Pattern
Generated UserController checks session through Better Auth:
import { auth } from "../lib/auth";
import { fromNodeHeaders } from "better-auth/node";
import { UnauthorizedError } from "../lib/errors";
export const UserController = {
async getProfile(req, res) {
const session = await auth.api.getSession({
headers: fromNodeHeaders(req.headers),
});
if (!session) {
throw new UnauthorizedError("Not authenticated");
}
return res.json({ user: session.user });
},
};Troubleshooting
Module 'auth' not found: runnpx zuro-cli add authinside a Zuro project.BETTER_AUTH_URLissues: set it to your backend origin (for examplehttp://localhost:3000).- migration errors: verify
DATABASE_URLand database existence, then rerun migration commands. 401 Not authenticatedon/api/users/me: include session cookie from login.