diff --git a/src/middlewares/authentication.ts b/src/middlewares/authentication.ts index 83abf9d..64bb5c0 100644 --- a/src/middlewares/authentication.ts +++ b/src/middlewares/authentication.ts @@ -94,29 +94,31 @@ const verifyToken = async (accessToken: string) => { try { await setUp(awsRegion, awsPoolId); - if (accessToken) { - const user: any = decode(accessToken, { complete: true }); - - if (user === null) { - throw new UnauthorizedException(); - } - - const { kid } = user.header; - const pem = pems.filter((item: any) => item[kid]); - const pemValue: any = pem[0][kid]; - - if (!pem) { - throw new UnauthorizedException(); - } - - verify(accessToken, pemValue, (err: any) => { - if (err) { - throw new UnauthorizedException(); - } - - return; - }); + if (!accessToken) { + throw new UnauthorizedException(); } + + const user: any = decode(accessToken, { complete: true }); + + if (user === null) { + throw new UnauthorizedException(); + } + + const { kid } = user.header; + const pem = pems.filter((item: any) => item[kid]); + const pemValue: any = pem[0][kid]; + + if (!pem) { + throw new UnauthorizedException(); + } + + verify(accessToken, pemValue, (err: any) => { + if (err) { + throw new UnauthorizedException(); + } + + return; + }); } catch (error) { throw new UnauthorizedException(); }