mirror of
https://github.com/sasjs/server.git
synced 2026-01-08 07:00:04 +00:00
chore(merge): Merge branch 'master' into authentication-with-jwt
This commit is contained in:
26
api/src/utils/verifyTokenInDB.ts
Normal file
26
api/src/utils/verifyTokenInDB.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import User from '../model/User'
|
||||
|
||||
export const verifyTokenInDB = async (
|
||||
userId: number,
|
||||
clientId: string,
|
||||
token: string,
|
||||
tokenType: 'accessToken' | 'refreshToken'
|
||||
) => {
|
||||
const dbUser = await User.findOne({ id: userId })
|
||||
|
||||
if (!dbUser) return undefined
|
||||
|
||||
const currentTokenObj = dbUser.tokens.find(
|
||||
(tokenObj: any) => tokenObj.clientId === clientId
|
||||
)
|
||||
|
||||
return currentTokenObj?.[tokenType] === token
|
||||
? {
|
||||
userId: dbUser.id,
|
||||
clientId,
|
||||
username: dbUser.username,
|
||||
isAdmin: dbUser.isAdmin,
|
||||
isActive: dbUser.isActive
|
||||
}
|
||||
: undefined
|
||||
}
|
||||
Reference in New Issue
Block a user