1
0
mirror of https://github.com/sasjs/server.git synced 2025-12-10 11:24:35 +00:00

fix: call jwt.verify in synchronous way

This commit is contained in:
2022-08-02 23:05:42 +05:00
parent f978814ca7
commit 254bc07da7

View File

@@ -93,27 +93,24 @@ const authenticateToken = async (
try {
if (!token) throw 'Unauthorized'
jwt.verify(token, key, async (err: any, data: any) => {
if (err) throw 'Unauthorized'
const data: any = jwt.verify(token, key)
// verify this valid token's entry in DB
const user = await verifyTokenInDB(
data?.userId,
data?.clientId,
token,
tokenType
)
const user = await verifyTokenInDB(
data?.userId,
data?.clientId,
token,
tokenType
)
if (user) {
if (user.isActive) {
req.user = user
if (tokenType === 'accessToken') req.accessToken = token
return next()
} else throw 'Unauthorized'
}
if (user) {
if (user.isActive) {
req.user = user
if (tokenType === 'accessToken') req.accessToken = token
return next()
} else throw 'Unauthorized'
}
throw 'Unauthorized'
})
throw 'Unauthorized'
} catch (error) {
if (await isPublicRoute(req)) {
req.user = publicUser