|
|
|
@ -21,7 +21,6 @@ export class AuthService { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async login(dto: LoginUserDto) { |
|
|
|
|
try { |
|
|
|
|
const user = await this.userService.findByName(dto.name); |
|
|
|
|
if (!user) throw new UnauthorizedException('Login failed'); |
|
|
|
|
|
|
|
|
@ -30,20 +29,10 @@ export class AuthService { |
|
|
|
|
|
|
|
|
|
const payload = { username: user.name, sub: user.id }; |
|
|
|
|
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) { |
|
|
|
|
try { |
|
|
|
|
const hashed = await bcrypt.hash(dto.password, 10); |
|
|
|
|
return this.userService.create({ ...dto, password: hashed }); |
|
|
|
|
} catch (error) { |
|
|
|
|
throw new BadRequestException('Signup failed'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|