sessionId from JWT into context for resolver

This commit is contained in:
Moriz Wahl 2021-08-30 16:29:11 +02:00
parent 7eec6faace
commit b2cdc69716
5 changed files with 13 additions and 10 deletions

View File

@ -7,7 +7,10 @@ import decode from '../jwt/decode'
export const isAuthorized: AuthChecker<any> = ({ root, args, context, info }, roles) => {
if (context.token) {
const decoded = decode(context.token)
if (decoded.sessionId && decoded.sessionId !== 0) return true
if (decoded.sessionId && decoded.sessionId !== 0) {
context.sessionId = decoded.sessionId
return true
}
}
return false
}

View File

@ -2,9 +2,6 @@ import { ArgsType, Field, Int } from 'type-graphql'
@ArgsType()
export class TransactionListInput {
@Field(() => Number)
sessionId: number
@Field(() => Int)
firstPage: number

View File

@ -1,4 +1,7 @@
import { Resolver, Query, Args, Authorized } from 'type-graphql'
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
import { Resolver, Query, Args, Authorized, Ctx } from 'type-graphql'
import CONFIG from '../../config'
import { TransactionList } from '../models/Transaction'
import { TransactionListInput, TransactionSendArgs } from '../inputs/TransactionInput'
@ -9,10 +12,11 @@ export class TransactionResolver {
@Authorized()
@Query(() => TransactionList)
async transactionList(
@Args() { sessionId, firstPage = 1, items = 25, order = 'DESC' }: TransactionListInput,
@Args() { firstPage = 1, items = 25, order = 'DESC' }: TransactionListInput,
@Ctx() context: any,
): Promise<TransactionList> {
const result = await apiGet(
`${CONFIG.COMMUNITY_API_URL}listTransactions/${firstPage}/${items}/${order}/${sessionId}`,
`${CONFIG.COMMUNITY_API_URL}listTransactions/${firstPage}/${items}/${order}/${context.sessionId}`,
)
if (!result.success) throw new Error(result.data)
return new TransactionList(result.data)

View File

@ -56,8 +56,8 @@ export const updateUserInfos = gql`
`
export const transactionsQuery = gql`
query($sessionId: Float!, $firstPage: Int = 1, $items: Int = 25, $order: String = "DESC") {
transactionList(sessionId: $sessionId, firstPage: $firstPage, items: $items, order: $order) {
query($firstPage: Int = 1, $items: Int = 25, $order: String = "DESC") {
transactionList(firstPage: $firstPage, items: $items, order: $order) {
gdtSum
count
balance

View File

@ -111,7 +111,6 @@ export default {
.query({
query: transactionsQuery,
variables: {
sessionId: this.$store.state.sessionId,
firstPage: pagination.firstPage,
items: pagination.items,
},