From 65efced999cee0cfdd8c023d2b4cc36265e39676 Mon Sep 17 00:00:00 2001 From: simeng-li Date: Fri, 26 Jul 2024 12:13:59 +0800 Subject: [PATCH] fix(core): fix api payload fix api payload --- .../backup-code-verification.ts | 43 ++++++++++++------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/packages/core/src/routes/experience/verification-routes/backup-code-verification.ts b/packages/core/src/routes/experience/verification-routes/backup-code-verification.ts index be4488299..7b5169179 100644 --- a/packages/core/src/routes/experience/verification-routes/backup-code-verification.ts +++ b/packages/core/src/routes/experience/verification-routes/backup-code-verification.ts @@ -18,29 +18,40 @@ export default function backupCodeVerificationRoutes { - const { experienceInteraction } = ctx; + router.post( + `${experienceRoutes.verification}/backup-code/generate`, + koaGuard({ + status: [200, 400], + response: z.object({ + verificationId: z.string(), + codes: z.array(z.string()), + }), + }), + async (ctx, next) => { + const { experienceInteraction } = ctx; - assertThat(experienceInteraction.identifiedUserId, 'session.identifier_not_found'); + assertThat(experienceInteraction.identifiedUserId, 'session.identifier_not_found'); - const backupCodeVerificationRecord = BackupCodeVerification.create( - libraries, - queries, - experienceInteraction.identifiedUserId - ); + const backupCodeVerificationRecord = BackupCodeVerification.create( + libraries, + queries, + experienceInteraction.identifiedUserId + ); - backupCodeVerificationRecord.generate(); + const codes = backupCodeVerificationRecord.generate(); - ctx.experienceInteraction.setVerificationRecord(backupCodeVerificationRecord); + ctx.experienceInteraction.setVerificationRecord(backupCodeVerificationRecord); - await ctx.experienceInteraction.save(); + await ctx.experienceInteraction.save(); - ctx.body = { - verificationId: backupCodeVerificationRecord.id, - }; + ctx.body = { + verificationId: backupCodeVerificationRecord.id, + codes, + }; - return next(); - }); + return next(); + } + ); router.post( `${experienceRoutes.verification}/backup-code/generate`,