mirror of
https://github.com/sasjs/server.git
synced 2025-12-11 19:44:35 +00:00
fix: call jwt.verify in synchronous way
This commit is contained in:
@@ -93,27 +93,24 @@ const authenticateToken = async (
|
|||||||
try {
|
try {
|
||||||
if (!token) throw 'Unauthorized'
|
if (!token) throw 'Unauthorized'
|
||||||
|
|
||||||
jwt.verify(token, key, async (err: any, data: any) => {
|
const data: any = jwt.verify(token, key)
|
||||||
if (err) throw 'Unauthorized'
|
|
||||||
|
|
||||||
// verify this valid token's entry in DB
|
const user = await verifyTokenInDB(
|
||||||
const user = await verifyTokenInDB(
|
data?.userId,
|
||||||
data?.userId,
|
data?.clientId,
|
||||||
data?.clientId,
|
token,
|
||||||
token,
|
tokenType
|
||||||
tokenType
|
)
|
||||||
)
|
|
||||||
|
|
||||||
if (user) {
|
if (user) {
|
||||||
if (user.isActive) {
|
if (user.isActive) {
|
||||||
req.user = user
|
req.user = user
|
||||||
if (tokenType === 'accessToken') req.accessToken = token
|
if (tokenType === 'accessToken') req.accessToken = token
|
||||||
return next()
|
return next()
|
||||||
} else throw 'Unauthorized'
|
} else throw 'Unauthorized'
|
||||||
}
|
}
|
||||||
|
|
||||||
throw 'Unauthorized'
|
throw 'Unauthorized'
|
||||||
})
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (await isPublicRoute(req)) {
|
if (await isPublicRoute(req)) {
|
||||||
req.user = publicUser
|
req.user = publicUser
|
||||||
|
|||||||
Reference in New Issue
Block a user