be
This commit is contained in:
32
backend/dist/auth/auth.service.js
vendored
32
backend/dist/auth/auth.service.js
vendored
@@ -30,30 +30,18 @@ let AuthService = class AuthService {
|
||||
return null;
|
||||
}
|
||||
async login(dto) {
|
||||
try {
|
||||
const user = await this.userService.findByName(dto.name);
|
||||
if (!user)
|
||||
throw new common_1.UnauthorizedException('Login failed');
|
||||
const passwordCheck = await bcrypt.compare(dto.password, user.password);
|
||||
if (!passwordCheck)
|
||||
throw new common_1.UnauthorizedException('Login failed');
|
||||
const payload = { username: user.name, sub: user.id };
|
||||
return { access_token: this.jwtService.sign(payload) };
|
||||
}
|
||||
catch (error) {
|
||||
if (error instanceof common_1.UnauthorizedException)
|
||||
throw error;
|
||||
throw new common_1.InternalServerErrorException('Login failed (Internal)');
|
||||
}
|
||||
const user = await this.userService.findByName(dto.name);
|
||||
if (!user)
|
||||
throw new common_1.UnauthorizedException('Login failed');
|
||||
const passwordCheck = await bcrypt.compare(dto.password, user.password);
|
||||
if (!passwordCheck)
|
||||
throw new common_1.UnauthorizedException('Login failed');
|
||||
const payload = { username: user.name, sub: user.id };
|
||||
return { access_token: this.jwtService.sign(payload) };
|
||||
}
|
||||
async signup(dto) {
|
||||
try {
|
||||
const hashed = await bcrypt.hash(dto.password, 10);
|
||||
return this.userService.create({ ...dto, password: hashed });
|
||||
}
|
||||
catch (error) {
|
||||
throw new common_1.BadRequestException('Signup failed');
|
||||
}
|
||||
const hashed = await bcrypt.hash(dto.password, 10);
|
||||
return this.userService.create({ ...dto, password: hashed });
|
||||
}
|
||||
};
|
||||
exports.AuthService = AuthService;
|
||||
|
Reference in New Issue
Block a user