mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
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:
parent
674bf789c4
commit
e41d2c543c
@ -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);
|
||||
}
|
||||
});
|
||||
10
types/express-jwt/index.d.ts
vendored
10
types/express-jwt/index.d.ts
vendored
@ -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 {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user