diff --git a/backend/src/graphql/directive/isAuthorized.ts b/backend/src/graphql/directive/isAuthorized.ts index 84756c45a..5c6d6f6f0 100644 --- a/backend/src/graphql/directive/isAuthorized.ts +++ b/backend/src/graphql/directive/isAuthorized.ts @@ -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 = async ({ context }, rights) => { context.role = ROLE_UNAUTHORIZED // unauthorized user diff --git a/backend/src/graphql/resolver/UserResolver.ts b/backend/src/graphql/resolver/UserResolver.ts index cacee6fc8..84698fbca 100644 --- a/backend/src/graphql/resolver/UserResolver.ts +++ b/backend/src/graphql/resolver/UserResolver.ts @@ -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 { + async verifyLogin(@Ctx() context: Context): Promise { // 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 { 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 { 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 { + async hasElopage(@Ctx() context: Context): Promise { const userEntity = context.user if (!userEntity) { return false