Files
DefinitelyTyped/types/express-jwt/express-jwt-tests.ts
Sl1MBoy e41d2c543c Added UnauthorizedError class to @types/express-jwt. (#18137)
* Added UnauthorizedError class.

* Updated definition to match gridstack v0.3.0

* Revert "Updated definition to match gridstack v0.3.0"

This reverts commit 2e1f194e68ffd914af08e1f6265cdc7ffb9f44f4.

Commited to wrong branch
2017-07-24 08:56:01 -07:00

31 lines
687 B
TypeScript

import express = require('express');
import jwt = require('express-jwt');
import unless = require('express-unless');
var app = express();
app.use(jwt({
secret: 'shhhhhhared-secret'
}));
app.use(jwt({
secret: 'shhhhhhared-secret',
userProperty: 'auth'
}));
var jwtCheck = jwt({
secret: 'shhhhhhared-secret'
});
jwtCheck.unless = unless;
app.use(jwtCheck.unless({ path: '/api/login' }));
app.use(function (err: any, req: express.Request, res: express.Response, next: express.NextFunction) {
if (err) {
if (err instanceof jwt.UnauthorizedError) {
res.status(err.status);
res.end();
}
} else {
next(err);
}
});