mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
encode buffer to hex when decoding the jwt, not everytime we use it
This commit is contained in:
parent
0341ae0d13
commit
8eb5c74ba8
@ -10,7 +10,7 @@ const isAuthorized: AuthChecker<any> = async (
|
||||
) => {
|
||||
if (context.token) {
|
||||
const decoded = decode(context.token)
|
||||
context.pubKey = decoded.pubKey
|
||||
context.pubKey = Buffer.from(decoded.pubKey).toString('hex')
|
||||
context.setHeaders.push({ key: 'token', value: encode(decoded.pubKey) })
|
||||
return true
|
||||
}
|
||||
|
||||
@ -18,8 +18,7 @@ export class BalanceResolver {
|
||||
const balanceRepository = getCustomRepository(BalanceRepository)
|
||||
const userRepository = getCustomRepository(UserRepository)
|
||||
|
||||
const pubKeyString = Buffer.from(context.pubKey).toString('hex')
|
||||
const userEntity = await userRepository.findByPubkeyHex(pubKeyString)
|
||||
const userEntity = await userRepository.findByPubkeyHex(context.pubKey)
|
||||
const balanceEntity = await balanceRepository.findByUser(userEntity.id)
|
||||
const now = new Date()
|
||||
|
||||
|
||||
@ -22,8 +22,7 @@ export class GdtResolver {
|
||||
): Promise<GdtEntryList> {
|
||||
// load user
|
||||
const userRepository = getCustomRepository(UserRepository)
|
||||
const pubKeyString = Buffer.from(context.pubKey).toString('hex')
|
||||
const userEntity = await userRepository.findByPubkeyHex(pubKeyString)
|
||||
const userEntity = await userRepository.findByPubkeyHex(context.pubKey)
|
||||
|
||||
const resultGDT = await apiGet(
|
||||
`${CONFIG.GDT_API_URL}/GdtEntries/listPerEmailApi/${userEntity.email}/${currentPage}/${pageSize}/${order}`,
|
||||
|
||||
@ -473,8 +473,7 @@ export class TransactionResolver {
|
||||
): Promise<TransactionList> {
|
||||
// load user
|
||||
const userRepository = getCustomRepository(UserRepository)
|
||||
const pubKeyString = Buffer.from(context.pubKey).toString('hex')
|
||||
const userEntity = await userRepository.findByPubkeyHex(pubKeyString)
|
||||
const userEntity = await userRepository.findByPubkeyHex(context.pubKey)
|
||||
|
||||
const transactions = await listTransactions(currentPage, pageSize, order, userEntity)
|
||||
|
||||
@ -509,8 +508,7 @@ export class TransactionResolver {
|
||||
// TODO this is subject to replay attacks
|
||||
// validate sender user (logged in)
|
||||
const userRepository = getCustomRepository(UserRepository)
|
||||
const pubKeyString = Buffer.from(context.pubKey).toString('hex')
|
||||
const senderUser = await userRepository.findByPubkeyHex(pubKeyString)
|
||||
const senderUser = await userRepository.findByPubkeyHex(context.pubKey)
|
||||
if (senderUser.pubkey.length !== 32) {
|
||||
throw new Error('invalid sender public key')
|
||||
}
|
||||
|
||||
@ -621,8 +621,7 @@ export class UserResolver {
|
||||
@Query(() => Boolean)
|
||||
async hasElopage(@Ctx() context: any): Promise<boolean> {
|
||||
const userRepository = getCustomRepository(UserRepository)
|
||||
const pubKey = Buffer.from(context.pubKey).toString('hex')
|
||||
const userEntity = await userRepository.findByPubkeyHex(pubKey).catch()
|
||||
const userEntity = await userRepository.findByPubkeyHex(context.pubKey).catch()
|
||||
if (!userEntity) {
|
||||
return false
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user