User => Player
This commit is contained in:
@ -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 }),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user