Peace 3 weeks ago
parent 6b009b7c22
commit 11af12a806
  1. 15
      backend/src/auth/auth.service.ts

@ -21,8 +21,7 @@ export class AuthService {
} }
async login(dto: LoginUserDto) { async login(dto: LoginUserDto) {
try { const user = await this.userService.findByName(dto.name);
const user = await this.userService.findByName(dto.name);
if (!user) throw new UnauthorizedException('Login failed'); if (!user) throw new UnauthorizedException('Login failed');
const passwordCheck = await bcrypt.compare(dto.password, user.password); const passwordCheck = await bcrypt.compare(dto.password, user.password);
@ -30,20 +29,10 @@ export class AuthService {
const payload = { username: user.name, sub: user.id }; const payload = { username: user.name, sub: user.id };
return { access_token: this.jwtService.sign(payload) }; return { access_token: this.jwtService.sign(payload) };
} catch (error) {
if (error instanceof UnauthorizedException) throw error;
throw new InternalServerErrorException('Login failed (Internal)');
}
} }
async signup(dto: CreateUserDto) { async signup(dto: CreateUserDto) {
try { const hashed = await bcrypt.hash(dto.password, 10);
const hashed = await bcrypt.hash(dto.password, 10);
return this.userService.create({ ...dto, password: hashed }); return this.userService.create({ ...dto, password: hashed });
} catch (error) {
throw new BadRequestException('Signup failed');
}
} }
} }

Loading…
Cancel
Save