Skip to content
atarashi
Documentation menu

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

PromptFlagTypeDefault
auth.expiry--auth-expiryinput"7d"

Files it writes

  • src/lib/jwt.ts (when provides('language:typescript'))
  • src/lib/jwt.js (when provides('language:javascript'))
  • src/lib/password.ts (when provides('language:typescript'))
  • src/lib/password.js (when provides('language:javascript'))
  • src/middlewares/auth.ts (when provides('language:typescript') && has('http/express'))
  • src/middlewares/auth.js (when provides('language:javascript') && has('http/express'))

Dependencies

  • jsonwebtoken@^9.0.2
  • bcryptjs@^3.0.2
  • cookie-parser@^1.4.7 (when has('http/express'))

Development only:

  • @types/jsonwebtoken@^9.0.10 (when provides('language:typescript'))
  • @types/bcryptjs@^3.0.0 (when provides('language:typescript'))
  • @types/cookie-parser@^1.4.9 (when provides('language:typescript') && has('http/express'))

Environment

VariableRequiredDescription
JWT_SECRETyesSigning key for access tokens; at least 32 characters
JWT_EXPIRES_INnoAccess token lifetime, e.g. 30m, 12h, 7d

What it contributes to other files

FileSlotLine
src/config/env.ts|jsenv-schemaJWT_SECRET: z.string().min(32, 'JWT_SECRET must be at least 32 characters'),
src/config/env.ts|jsenv-schemaJWT_EXPIRES_IN: z.string().default('{{#when "answers.auth.expiry"}}{{expr "answers.auth.expiry"}}{{else}}7d{{/when}}'),
src/app.ts|jsimportsimport cookieParser from 'cookie-parser';
src/app.ts|jsmiddlewareapp.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.