From ea0ad5cd999c9859a93bb32405d1d9fa5c794ead Mon Sep 17 00:00:00 2001 From: Abdul Rahman Reza Date: Sat, 30 Nov 2024 22:55:21 +0700 Subject: [PATCH] update jwt --- src/helpers/jwt.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/helpers/jwt.ts b/src/helpers/jwt.ts index 1db12f7..1a3ecba 100644 --- a/src/helpers/jwt.ts +++ b/src/helpers/jwt.ts @@ -15,7 +15,15 @@ export default class JwtHelper { app.use( expressjwt({ - secret: publicKey, algorithms: ["RS256"] + secret: publicKey, algorithms: ["RS256"], + getToken: function fromHeaderOrQuerystring(req): any { + if (req.headers.authorization && req.headers.authorization.split(' ')[0] === 'Bearer') { + return req.headers.authorization.split(' ')[1]; + } else if (req.query && req.query.token) { + return req.query.token; + } + return null; + }, }).unless({ path: ["/token"] }), function (req: Request, res: Response, next: NextFunction) { if (!req.auth?.data.id) {