This commit is contained in:
2025-07-16 16:25:16 +09:00
parent 11af12a806
commit 8135650344
34 changed files with 301 additions and 41 deletions

View File

@@ -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;