MCPcopy Create free account
hub / github.com/bewcloud/bewcloud / validate

Method validate

lib/models/user.ts:272–304  ·  view source on GitHub ↗
(
    user: User,
    verificationId: string,
    code: string,
    type: VerificationCode['verification']['type'],
  )

Source from the content-addressed store, hash-verified

270 }
271
272 static async validate(
273 user: User,
274 verificationId: string,
275 code: string,
276 type: VerificationCode['verification']['type'],
277 ) {
278 const verificationCode = (await db.query<VerificationCode>(
279 sql`SELECT * FROM "bewcloud_verification_codes"
280 WHERE "user_id" = $1 AND
281 "code" = $2 AND
282 "verification" ->> 'type' = $3 AND
283 "verification" ->> 'id' = $4 AND
284 "expires_at" > now()
285 LIMIT 1`,
286 [
287 user.id,
288 code,
289 type,
290 verificationId,
291 ],
292 ))[0];
293
294 if (verificationCode) {
295 await db.query(
296 sql`DELETE FROM "bewcloud_verification_codes" WHERE "id" = $1`,
297 [
298 verificationCode.id,
299 ],
300 );
301 } else {
302 throw new Error('Not Found');
303 }
304 }
305}

Callers 3

postFunction · 0.80
postFunction · 0.80
verifyCodeMethod · 0.80

Calls 1

queryMethod · 0.80

Tested by

no test coverage detected