MCPcopy Index your code
hub / github.com/simstudioai/sim / storeOTP

Function storeOTP

apps/sim/lib/core/security/otp.ts:77–109  ·  view source on GitHub ↗
(
  kind: DeploymentKind,
  deploymentId: string,
  email: string,
  otp: string
)

Source from the content-addressed store, hash-verified

75 * `verification` table based on the configured storage method.
76 */
77export async function storeOTP(
78 kind: DeploymentKind,
79 deploymentId: string,
80 email: string,
81 otp: string
82): Promise<void> {
83 const keys = OTP_KEYS[kind]
84 const value = encodeOTPValue(otp, 0)
85 const storageMethod = getStorageMethod()
86
87 if (storageMethod === 'redis') {
88 const redis = getRedisClient()
89 if (!redis) throw new Error('Redis configured but client unavailable')
90 await redis.set(keys.redisKey(email, deploymentId), value, 'EX', OTP_EXPIRY_SECONDS)
91 return
92 }
93
94 const now = new Date()
95 const expiresAt = new Date(now.getTime() + OTP_EXPIRY_MS)
96 const identifier = keys.dbIdentifier(email, deploymentId)
97
98 await db.transaction(async (tx) => {
99 await tx.delete(verification).where(eq(verification.identifier, identifier))
100 await tx.insert(verification).values({
101 id: generateId(),
102 identifier,
103 value,
104 expiresAt,
105 createdAt: now,
106 updatedAt: now,
107 })
108 })
109}
110
111export async function getOTP(
112 kind: DeploymentKind,

Callers 2

route.tsFile · 0.90
route.tsFile · 0.90

Calls 7

getStorageMethodFunction · 0.90
getRedisClientFunction · 0.90
generateIdFunction · 0.90
encodeOTPValueFunction · 0.85
setMethod · 0.65
deleteMethod · 0.65
eqFunction · 0.50

Tested by

no test coverage detected