mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2026-01-19 11:21:26 +00:00
* lint @typescript-eslint/recommended * lint @typescript-eslint/recommended-requiring-type-checking fix type not detected locally due to wierd uuid typings missing save error not reported locally --------- Co-authored-by: Wolfgang Huß <wolle.huss@pjannto.com>
45 lines
1.4 KiB
TypeScript
45 lines
1.4 KiB
TypeScript
/* eslint-disable @typescript-eslint/no-unsafe-return */
|
|
/* eslint-disable @typescript-eslint/no-unsafe-call */
|
|
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
|
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
|
import jwt from 'jsonwebtoken'
|
|
|
|
import CONFIG from '@config/index'
|
|
|
|
export default async (driver, authorizationHeader) => {
|
|
if (!authorizationHeader) return null
|
|
const token = authorizationHeader.replace('Bearer ', '')
|
|
let id = null
|
|
try {
|
|
const decoded = await jwt.verify(token, CONFIG.JWT_SECRET)
|
|
id = decoded.sub
|
|
// eslint-disable-next-line no-catch-all/no-catch-all
|
|
} catch (err) {
|
|
return null
|
|
}
|
|
const session = driver.session()
|
|
|
|
const writeTxResultPromise = session.writeTransaction(async (transaction) => {
|
|
const updateUserLastActiveTransactionResponse = await transaction.run(
|
|
`
|
|
MATCH (user:User {id: $id, deleted: false, disabled: false })
|
|
SET user.lastActiveAt = toString(datetime())
|
|
RETURN user {.id, .slug, .name, .role, .disabled, .actorId}
|
|
LIMIT 1
|
|
`,
|
|
{ id },
|
|
)
|
|
return updateUserLastActiveTransactionResponse.records.map((record) => record.get('user'))
|
|
})
|
|
try {
|
|
const [currentUser] = await writeTxResultPromise
|
|
if (!currentUser) return null
|
|
return {
|
|
token,
|
|
...currentUser,
|
|
}
|
|
} finally {
|
|
session.close()
|
|
}
|
|
}
|