added user info in sign in and sign up return

This commit is contained in:
Kevsl 2024-06-07 14:37:41 +02:00
parent b194d084cf
commit 73fd9bf8a1
3 changed files with 16 additions and 6 deletions

View File

@ -59,20 +59,26 @@ export class AuthService {
} }
async signin(dto: AuthLoginDto) { async signin(dto: AuthLoginDto) {
const user = await this.prisma.user.findUnique({ const userDatas = await this.prisma.user.findUnique({
where: { where: {
email: dto.email, email: dto.email,
}, },
include: {
UserHasCrypto: {
include: { Crypto: true },
},
Role: true,
},
}); });
if (!user) throw new ForbiddenException('Credentials incorrect'); if (!userDatas) throw new ForbiddenException('Credentials incorrect');
const pwMatches = await argon.verify(user.hash, dto.password); const pwMatches = await argon.verify(userDatas.hash, dto.password);
if (!pwMatches) throw new ForbiddenException('Credentials incorrect'); if (!pwMatches) throw new ForbiddenException('Credentials incorrect');
return this.signToken(user); return this.signToken(userDatas);
} }
async signToken(user: User): Promise<{ access_token: string; user: User }> { async signToken(user: any): Promise<{ access_token: string; user: User }> {
const payload = { const payload = {
sub: user.id, sub: user.id,
email: user.email, email: user.email,

View File

@ -14,7 +14,11 @@ export class UserService {
id: userId, id: userId,
}, },
include: { include: {
UserHasCrypto: true, UserHasCrypto: {
include: {
Crypto: true,
},
},
}, },
}); });
return user; return user;

0
src/utils/types.ts Normal file
View File