summaryrefslogtreecommitdiff
path: root/lib/users/verifyOtp.ts
blob: 7b25ed49470f13001595fe14394aad9e1cf87ff5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// lib/users/verifyOtp.ts
import { findEmailTemp, findEmailandOtp } from '@/lib/users/service'

// "email과 code가 맞으면 유저 정보, 아니면 null" 형태로 작성
export async function verifyOtp(email: string, code: string) {
  // DB에서 email과 code가 맞는지, 만료 안됐는지 검증
  const otpRecord = await findEmailandOtp(email, code)
  if (!otpRecord) {
    return null
  }

  // 만료 체크
  if (otpRecord.otpExpires && otpRecord.otpExpires < new Date()) {
    return null
  }

  // 여기서 otpRecord에 유저 정보가 있다고 가정
  // 예: otpRecord.userId, otpRecord.userName, otpRecord.email 등
  // 실제 DB 설계에 맞춰 필드명을 조정하세요.
  return {
    email: otpRecord.email,
    name: otpRecord.name,
    id: otpRecord.id,
    imageUrl: otpRecord.imageUrl,
    companyId: otpRecord.companyId,
    techCompanyId: otpRecord.techCompanyId,
    domain: otpRecord.domain,
  }
}

export async function verifyOtpTemp(email: string) {
  // DB에서 email과 code가 맞는지, 만료 안됐는지 검증
  const otpRecord = await findEmailTemp(email)
  if (!otpRecord) {
    return null
  }


  // 여기서 otpRecord에 유저 정보가 있다고 가정
  // 예: otpRecord.userId, otpRecord.userName, otpRecord.email 등
  // 실제 DB 설계에 맞춰 필드명을 조정하세요.
  return {
    email: otpRecord.email,
    name: otpRecord.name,
    id: otpRecord.id,
    imageUrl: otpRecord.imageUrl,
    companyId: otpRecord.companyId,
    techCompanyId: otpRecord.techCompanyId,
    domain: otpRecord.domain,
  }
}


export async function verifyExternalCredentials(username: string, password: string) {
  // DB에서 email과 code가 맞는지, 만료 안됐는지 검증
  const otpRecord = await findEmailandOtp(username, password)
  if (!otpRecord) {
    return null
  }

  // 만료 체크
  if (otpRecord.otpExpires && otpRecord.otpExpires < new Date()) {
    return null
  }

  // 여기서 otpRecord에 유저 정보가 있다고 가정
  // 예: otpRecord.userId, otpRecord.userName, otpRecord.email 등
  // 실제 DB 설계에 맞춰 필드명을 조정하세요.
  return {
    email: otpRecord.email,
    name: otpRecord.name,
    id: otpRecord.id,
    imageUrl: otpRecord.imageUrl,
    companyId: otpRecord.companyId,
    techCompanyId: otpRecord.techCompanyId,
    domain: otpRecord.domain,
  }
}