- 로그인 이후 access/refresh token 생성 및 반환 로직 구현
This commit is contained in:
@@ -5,12 +5,14 @@ import { MailerService } from "src/util/mailer/mailer.service";
|
||||
import { Generator } from "src/util/generator";
|
||||
import Redis from "ioredis";
|
||||
import { Converter } from "src/util/converter";
|
||||
import { AuthService } from "src/middleware/auth/auth.service";
|
||||
|
||||
@Injectable()
|
||||
export class AccountService {
|
||||
constructor(
|
||||
private readonly accountRepo: AccountRepo
|
||||
, private readonly mailerService: MailerService
|
||||
, private readonly authService: AuthService
|
||||
, @Inject("REDIS") private readonly redis: Redis
|
||||
) {}
|
||||
|
||||
@@ -70,4 +72,41 @@ export class AccountService {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
async login(data: DTO.LoginRequest): Promise<DTO.LoginResponse> {
|
||||
const { type, id, password } = data;
|
||||
const queryResult = await this.accountRepo.login(type, id);
|
||||
const typeValue = type === 'email' ? '이메일' : '아이디';
|
||||
console.log(queryResult);
|
||||
if (!queryResult || (queryResult.length < 1)) {
|
||||
return {
|
||||
success: false,
|
||||
message: `존재하지 않는 ${typeValue} 입니다.`
|
||||
};
|
||||
}
|
||||
const hashedPassword = queryResult[0].password;
|
||||
const isPasswordMatch = Converter.comparePassword(password, hashedPassword);
|
||||
if (!isPasswordMatch) {
|
||||
return {
|
||||
success: false,
|
||||
message: `비밀번호가 맞지 않습니다.`
|
||||
};
|
||||
}
|
||||
|
||||
{
|
||||
const { id, accountId, name, nickname, email, status, isDeleted, birthday } = queryResult[0];
|
||||
|
||||
const payload = {
|
||||
id, accountId, name, nickname, email, status, isDeleted, birthday
|
||||
};
|
||||
|
||||
const { accessToken, refreshToken } = this.authService.generateTokens(payload);
|
||||
|
||||
return {
|
||||
success: true,
|
||||
accessToken: accessToken,
|
||||
refreshToken: refreshToken
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user