use Context interface in user resolver

This commit is contained in:
Moriz Wahl 2022-04-11 15:50:46 +02:00
parent 7ec35bbfb2
commit 57298a4d3a
2 changed files with 8 additions and 4 deletions

View File

@ -9,6 +9,7 @@ import { getCustomRepository } from '@dbTools/typeorm'
import { UserRepository } from '@repository/User'
import { INALIENABLE_RIGHTS } from '@/auth/INALIENABLE_RIGHTS'
import { ServerUser } from '@entity/ServerUser'
import { Context } from '@/server/context'
const isAuthorized: AuthChecker<any> = async ({ context }, rights) => {
context.role = ROLE_UNAUTHORIZED // unauthorized user

View File

@ -2,6 +2,7 @@
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
import fs from 'fs'
import { Context } from '@/server/context'
import { Resolver, Query, Args, Arg, Authorized, Ctx, UseMiddleware, Mutation } from 'type-graphql'
import { getConnection, getCustomRepository } from '@dbTools/typeorm'
import CONFIG from '@/config'
@ -192,9 +193,10 @@ export class UserResolver {
@Authorized([RIGHTS.VERIFY_LOGIN])
@Query(() => User)
@UseMiddleware(klicktippNewsletterStateMiddleware)
async verifyLogin(@Ctx() context: any): Promise<User> {
async verifyLogin(@Ctx() context: Context): Promise<User> {
// TODO refactor and do not have duplicate code with login(see below)
const userEntity = context.user
if (!userEntity) throw new Error('No user given!')
const user = new User(userEntity)
// user.pubkey = userEntity.pubKey.toString('hex')
// Elopage Status & Stored PublisherId
@ -218,7 +220,7 @@ export class UserResolver {
@UseMiddleware(klicktippNewsletterStateMiddleware)
async login(
@Args() { email, password, publisherId }: UnsecureLoginArgs,
@Ctx() context: any,
@Ctx() context: Context,
): Promise<User> {
email = email.trim().toLowerCase()
const dbUser = await DbUser.findOneOrFail({ email }, { withDeleted: true }).catch(() => {
@ -540,9 +542,10 @@ export class UserResolver {
passwordNew,
coinanimation,
}: UpdateUserInfosArgs,
@Ctx() context: any,
@Ctx() context: Context,
): Promise<boolean> {
const userEntity = context.user
if (!userEntity) throw new Error('No user given!')
if (firstName) {
userEntity.firstName = firstName
@ -619,7 +622,7 @@ export class UserResolver {
@Authorized([RIGHTS.HAS_ELOPAGE])
@Query(() => Boolean)
async hasElopage(@Ctx() context: any): Promise<boolean> {
async hasElopage(@Ctx() context: Context): Promise<boolean> {
const userEntity = context.user
if (!userEntity) {
return false