summaryrefslogtreecommitdiff
path: root/lib/users/send-otp.ts
diff options
context:
space:
mode:
authordujinkim <dujin.kim@dtsolution.co.kr>2025-06-11 12:18:38 +0000
committerdujinkim <dujin.kim@dtsolution.co.kr>2025-06-11 12:18:38 +0000
commitff902243a658067fae858a615c0629aa2e0a4837 (patch)
tree42d30e986d1cbfb282c644c01730cd053b816b7a /lib/users/send-otp.ts
parent42e38f41cb4c0b4bf9c08b71ed087cd7f0c7fc18 (diff)
(대표님) 20250611 21시 15분 OCR 등
Diffstat (limited to 'lib/users/send-otp.ts')
-rw-r--r--lib/users/send-otp.ts68
1 files changed, 34 insertions, 34 deletions
diff --git a/lib/users/send-otp.ts b/lib/users/send-otp.ts
index ecaf19a5..96d975a1 100644
--- a/lib/users/send-otp.ts
+++ b/lib/users/send-otp.ts
@@ -29,47 +29,47 @@ export async function sendOtpAction(email: string, lng: string) {
/////테스트 임시
// OTP 및 만료 시간 생성
- // const otp = Math.floor(100000 + Math.random() * 900000).toString();
- // const expires = new Date(Date.now() + 10 * 60 * 1000); // 10분 후 만료
- // const token = jwt.sign(
- // {
- // email,
- // otp,
- // exp: Math.floor(expires.getTime() / 1000),
- // },
- // process.env.JWT_SECRET!
- // );
+ const otp = Math.floor(100000 + Math.random() * 900000).toString();
+ const expires = new Date(Date.now() + 10 * 60 * 1000); // 10분 후 만료
+ const token = jwt.sign(
+ {
+ email,
+ otp,
+ exp: Math.floor(expires.getTime() / 1000),
+ },
+ process.env.JWT_SECRET!
+ );
// // DB에 OTP 추가
- // await addNewOtp(email, otp, new Date(), token, expires);
+ await addNewOtp(email, otp, new Date(), token, expires);
// // 이메일에서 사용할 URL 구성
- // const verificationUrl = `http://${host}/ko/login?token=${token}`;
+ const verificationUrl = `http://${host}/ko/login?token=${token}`;
- // // IP 정보로부터 지역 조회 (ip-api 사용)
- // const ip = headersList.get('x-forwarded-for')?.split(',')[0]?.trim() || '';
- // let location = '';
- // try {
- // const response = await fetch(`http://ip-api.com/json/${ip}?fields=country,city`);
- // const data = await response.json();
- // location = data.city && data.country ? `${data.city}, ${data.country}` : '';
- // } catch (error) {
- // // 위치 조회 실패 시 무시
- // }
+ // IP 정보로부터 지역 조회 (ip-api 사용)
+ const ip = headersList.get('x-forwarded-for')?.split(',')[0]?.trim() || '';
+ let location = '';
+ try {
+ const response = await fetch(`http://ip-api.com/json/${ip}?fields=country,city`);
+ const data = await response.json();
+ location = data.city && data.country ? `${data.city}, ${data.country}` : '';
+ } catch (error) {
+ // 위치 조회 실패 시 무시
+ }
// // OTP 이메일 발송
- // await sendEmail({
- // to: email,
- // subject: `${otp} - SHI eVCP Sign-in Verification`,
- // template: 'otp',
- // context: {
- // name: user.name,
- // otp,
- // verificationUrl,
- // location,
- // language: lng,
- // },
- // });
+ await sendEmail({
+ to: email,
+ subject: `${otp} - SHI eVCP Sign-in Verification`,
+ template: 'otp',
+ context: {
+ name: user.name,
+ otp,
+ verificationUrl,
+ location,
+ language: lng,
+ },
+ });
// 클라이언트로 반환할 수 있는 값
return {