mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-16 22:40:01 +08:00
* 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
31 lines
687 B
TypeScript
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);
|
|
}
|
|
}); |