User => Player

This commit is contained in:
2024-12-08 13:41:37 +01:00
parent c6da328023
commit 65576fc5b1
39 changed files with 193 additions and 240 deletions

View File

@ -9,17 +9,17 @@ export class AuthService {
constructor(private prisma: PrismaService, private jwtService: JwtService) {}
async login(name: string, password: string): Promise<AuthEntity> {
const user = await this.prisma.user.findUnique({ where: { name: name } })
if (!user) {
throw new NotFoundException(`Aucun⋅e utilisateur⋅rice avec pour nom ${name}`)
const player = await this.prisma.player.findUnique({ where: { name: name } })
if (!player) {
throw new NotFoundException(`Aucun⋅e joueur⋅se avec pour nom ${name}`)
}
const isPasswordValid = await bcrypt.compare(password, user.password)
const isPasswordValid = await bcrypt.compare(password, player.password)
if (!isPasswordValid) {
throw new UnauthorizedException('Mot de passe incorrect')
}
return {
accessToken: this.jwtService.sign({ userId: user.id }),
accessToken: this.jwtService.sign({ playerId: player.id }),
}
}
}