Typed express-jwt
Typescript Typings for express-jwt.
Installation
typings install --save express-jwt
Usage
import express = require('express');
import jwt = require('express-jwt');
const app = express();
interface User {
username: string;
admin: boolean;
}
app.get('/protected', jwt({ secret: 'shhhhhhared-secret' }), (req: express.Request & jwt.Authenticated<User>, res: express.Response) {
if (!req.user.admin) {
throw Object.assign(new Error('Admin rights required'), { status: 401 });
}
res.sendStatus(200);
});
Contributing
You can run them the tests with npm run build
and npm run test
.
Based on typings by Wonshik Kim