class AuthModelClass extends BaseModel {
@api()
async login(
ctx: Context,
email: string,
password: string
) {
// ์ฌ์ฉ์ ์ธ์ฆ ๋ก์ง
const user = await this.validateCredentials(email, password);
if (!user) {
throw new UnauthorizedException("์ด๋ฉ์ผ ๋๋ ๋น๋ฐ๋ฒํธ๊ฐ ์ฌ๋ฐ๋ฅด์ง ์์ต๋๋ค");
}
// ์ธ์
์ ์ฌ์ฉ์ ์ ๋ณด ์ ์ฅ
await ctx.passport.login(user);
return { success: true, user };
}
private async validateCredentials(email: string, password: string) {
// ์ค์ ์ธ์ฆ ๋ก์ง ๊ตฌํ
const user = await this.findByEmail(email);
if (!user) return null;
const isValid = await bcrypt.compare(password, user.passwordHash);
return isValid ? user : null;
}
}