mirror of
https://github.com/sasjs/server.git
synced 2026-01-11 08:20:04 +00:00
feat: JWT saved in DB + logout api added
This commit is contained in:
14
src/utils/removeTokensInDB.ts
Normal file
14
src/utils/removeTokensInDB.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import User from '../model/User'
|
||||
|
||||
export const removeTokensInDB = async (username: string, client_id: string) => {
|
||||
const user = await User.findOne({ username })
|
||||
|
||||
const tokenObjIndex = user.tokens.findIndex(
|
||||
(tokenObj: any) => tokenObj.clientid === client_id
|
||||
)
|
||||
|
||||
if (tokenObjIndex > -1) {
|
||||
user.tokens.splice(tokenObjIndex, 1)
|
||||
await user.save()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user