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
This commit is contained in:
Sl1MBoy 2017-07-24 17:56:01 +02:00 committed by Andy
parent 674bf789c4
commit e41d2c543c
2 changed files with 21 additions and 2 deletions

View File

@ -17,4 +17,15 @@ var jwtCheck = jwt({
secret: 'shhhhhhared-secret'
});
jwtCheck.unless = unless;
app.use(jwtCheck.unless({ path: '/api/login' }));
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);
}
});

View File

@ -1,6 +1,6 @@
// Type definitions for express-jwt
// Project: https://www.npmjs.org/package/express-jwt
// Definitions by: Wonshik Kim <https://github.com/wokim/>, Kacper Polak <https://github.com/kacepe>
// Definitions by: Wonshik Kim <https://github.com/wokim/>, Kacper Polak <https://github.com/kacepe>, Sl1MBoy <https://github.com/Sl1MBoy>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
import express = require('express');
@ -36,6 +36,14 @@ declare namespace jwt {
export interface RequestHandler extends express.RequestHandler {
unless: typeof unless;
}
export class UnauthorizedError extends Error {
name: string;
message: string;
code: string;
status: number;
inner: Error
}
}
declare global {
namespace Express {