This commit is contained in:
2025-07-18 15:02:46 +09:00
parent bf8c75f770
commit 766a2ad111
37 changed files with 1284 additions and 943 deletions

View File

@@ -21,28 +21,25 @@ let AuthService = class AuthService {
this.userService = userService;
this.jwtService = jwtService;
}
async validateUser(name, password) {
const user = await this.userService.findByName(name);
if (user && await bcrypt.compare(password, user.password)) {
const { password, ...rest } = user;
return rest;
}
return null;
}
async login(dto) {
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) {
const hashed = await bcrypt.hash(dto.password, 10);
return this.userService.create({ ...dto, password: hashed });
}
async login(dto) {
const user = await this.userService.findByName(dto.name);
if (!user || !await bcrypt.compare(dto.password, user.password))
throw new common_1.UnauthorizedException('Login failed');
const payload = { username: user.name, sub: user.id };
const token = this.jwtService.sign(payload);
return {
access_token: token,
user: {
id: user.id,
name: user.name,
email: user.email,
}
};
}
};
exports.AuthService = AuthService;
exports.AuthService = AuthService = __decorate([