fix: displayName return undefined and drop displayName from user table (#505)
This commit is contained in:
@ -8,6 +8,11 @@ import { VerifyInput } from './dto/verify.input';
|
||||
import { AuthService } from './services/auth.service';
|
||||
import { LoginToken } from './dto/login-token.entity';
|
||||
import { ChallengeInput } from './dto/challenge.input';
|
||||
import {
|
||||
PrismaSelect,
|
||||
PrismaSelector,
|
||||
} from 'src/decorators/prisma-select.decorator';
|
||||
import { Prisma } from '@prisma/client';
|
||||
|
||||
@Resolver()
|
||||
export class AuthResolver {
|
||||
@ -25,11 +30,21 @@ export class AuthResolver {
|
||||
}
|
||||
|
||||
@Mutation(() => Verify)
|
||||
async verify(@Args() verifyInput: VerifyInput): Promise<Verify> {
|
||||
async verify(
|
||||
@Args() verifyInput: VerifyInput,
|
||||
@PrismaSelector({
|
||||
modelName: 'User',
|
||||
defaultFields: { User: { id: true } },
|
||||
})
|
||||
prismaSelect: PrismaSelect<'User'>,
|
||||
): Promise<Verify> {
|
||||
const email = await this.tokenService.verifyLoginToken(
|
||||
verifyInput.loginToken,
|
||||
);
|
||||
const result = await this.authService.verify(email);
|
||||
const select = prismaSelect.valueOf('user') as Prisma.UserSelect & {
|
||||
id: true;
|
||||
};
|
||||
const result = await this.authService.verify(email, select);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -16,7 +16,13 @@ export class VerifyAuthController {
|
||||
const email = await this.tokenService.verifyLoginToken(
|
||||
verifyInput.loginToken,
|
||||
);
|
||||
const result = await this.authService.verify(email);
|
||||
const result = await this.authService.verify(email, {
|
||||
id: true,
|
||||
firstName: true,
|
||||
lastName: true,
|
||||
email: true,
|
||||
emailVerified: true,
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -5,5 +5,5 @@ import { User } from 'src/core/@generated/user/user.model';
|
||||
@ObjectType()
|
||||
export class Verify extends AuthTokens {
|
||||
@Field(() => User)
|
||||
user: User;
|
||||
user: Partial<User>;
|
||||
}
|
||||
|
||||
@ -11,6 +11,7 @@ import { RegisterInput } from '../dto/register.input';
|
||||
import { PASSWORD_REGEX, compareHash, hashPassword } from '../auth.util';
|
||||
import { Verify } from '../dto/verify.entity';
|
||||
import { TokenService } from './token.service';
|
||||
import { Prisma } from '@prisma/client';
|
||||
|
||||
export type UserPayload = {
|
||||
firstName: string;
|
||||
@ -74,11 +75,17 @@ export class AuthService {
|
||||
return user;
|
||||
}
|
||||
|
||||
async verify(email: string): Promise<Verify> {
|
||||
async verify(
|
||||
email: string,
|
||||
select: Prisma.UserSelect & {
|
||||
id: true;
|
||||
},
|
||||
): Promise<Verify> {
|
||||
const user = await this.userService.findUnique({
|
||||
where: {
|
||||
email,
|
||||
},
|
||||
select,
|
||||
});
|
||||
|
||||
assert(user, "This user doesn't exist", NotFoundException);
|
||||
|
||||
Reference in New Issue
Block a user