Skip to content

Commit

Permalink
restore requestProperty
Browse files Browse the repository at this point in the history
  • Loading branch information
jfromaniello committed Apr 25, 2022
1 parent eb7479b commit bf143d0
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/index.ts
Expand Up @@ -13,6 +13,7 @@ type Params = {
getToken?: TokenGetter,
isRevoked?: IsRevoked,
credentialsRequired?: boolean,
requestProperty?: string,
} & jwt.VerifyOptions;

export { UnauthorizedError } from './errors/UnauthorizedError';
Expand All @@ -32,7 +33,7 @@ export const expressjwt = (options: Params) => {
async () => options.secret as jwt.Secret;

const credentialsRequired = typeof options.credentialsRequired === 'undefined' ? true : options.credentialsRequired;

const requestProperty = typeof options.requestProperty === 'string' ? options.requestProperty : 'auth';

const middleware = async function (req: express.Request, res: express.Response, next: express.NextFunction) {
let token: string;
Expand Down Expand Up @@ -100,7 +101,7 @@ export const expressjwt = (options: Params) => {
}

const request = req as ExpressJwtRequest<jwt.JwtPayload | string>;
request.auth = decodedToken.payload;
request[requestProperty] = decodedToken.payload;
next();
} catch (err) {
return next(err);
Expand Down

0 comments on commit bf143d0

Please sign in to comment.