padlock-auth
v2.1.0
Published
Middleware & Services to implement token creation & validation for express app.
Maintainers
Readme
🔒 padlock-auth
Middleware & Services to implement token creation & validation for express app.
🚀 Quick start
- Install the package:
npm install padlock-auth- create the
.envfile in the project root:
touch .env- define the
JWT_SECRET_KEYvariable in the.envfile:
JWT_SECRET_KEY = "<your-random-string>"- Set the middleware for all protected routes:
router.post('/api/users', verifyTokenMiddleware, createUserController);- Create the token where you need it:
const token = Token.create({ userId: user.id });- (Optional) define the time the token will expire in the
.envfile (by default expires in 2 hours):
JWT_EXPIRES_IN = '2h'- (Optional and not recomendable) define if you want to disable the token verification in the
.envfile:
VERIFY_TOKEN = 'false'