auth/jwt
Stateless JWT auth: signing helpers, bcrypt password hashing and a bearer/cookie guard.
Provides: auth, auth:jwt
Requires: http, config:env
Conflicts with: auth
Options
| Prompt | Flag | Type | Default |
|---|---|---|---|
auth.expiry | --auth-expiry | input | "7d" |
Files it writes
src/lib/jwt.ts(whenprovides('language:typescript'))src/lib/jwt.js(whenprovides('language:javascript'))src/lib/password.ts(whenprovides('language:typescript'))src/lib/password.js(whenprovides('language:javascript'))src/middlewares/auth.ts(whenprovides('language:typescript') && has('http/express'))src/middlewares/auth.js(whenprovides('language:javascript') && has('http/express'))
Dependencies
jsonwebtoken@^9.0.2bcryptjs@^3.0.2cookie-parser@^1.4.7(whenhas('http/express'))
Development only:
@types/jsonwebtoken@^9.0.10(whenprovides('language:typescript'))@types/bcryptjs@^3.0.0(whenprovides('language:typescript'))@types/cookie-parser@^1.4.9(whenprovides('language:typescript') && has('http/express'))
Environment
| Variable | Required | Description |
|---|---|---|
JWT_SECRET | yes | Signing key for access tokens; at least 32 characters |
JWT_EXPIRES_IN | no | Access token lifetime, e.g. 30m, 12h, 7d |
What it contributes to other files
| File | Slot | Line |
|---|---|---|
src/config/env.ts|js | env-schema | JWT_SECRET: z.string().min(32, 'JWT_SECRET must be at least 32 characters'), |
src/config/env.ts|js | env-schema | JWT_EXPIRES_IN: z.string().default('{{#when "answers.auth.expiry"}}{{expr "answers.auth.expiry"}}{{else}}7d{{/when}}'), |
src/app.ts|js | imports | import cookieParser from 'cookie-parser'; |
src/app.ts|js | middleware | app.use(cookieParser()); |
Use it
atarashi new my-app --add auth/jwt
atarashi add auth/jwt
Version 1.0.0. Format reference: Authoring blueprints.
Part of the atarashi documentation, written and maintained by Gautam Suthar.