From 549cb66a92cbedf858bcf22360b49b9b14a17790 Mon Sep 17 00:00:00 2001 From: wangsijie Date: Wed, 30 Nov 2022 11:21:06 +0800 Subject: [PATCH] fix(core,schemas): fix continue flow with log and interaction merge --- packages/core/src/routes/session/passwordless.ts | 2 ++ packages/core/src/routes/session/utils.ts | 4 ++++ packages/schemas/src/types/log.ts | 14 ++++++++++++++ 3 files changed, 20 insertions(+) diff --git a/packages/core/src/routes/session/passwordless.ts b/packages/core/src/routes/session/passwordless.ts index c39ba6e0b..61f55326a 100644 --- a/packages/core/src/routes/session/passwordless.ts +++ b/packages/core/src/routes/session/passwordless.ts @@ -122,6 +122,7 @@ export default function passwordlessRoutes( } await assignVerificationResult(ctx, provider, { flow, phone }); + ctx.status = 204; return next(); } @@ -171,6 +172,7 @@ export default function passwordlessRoutes( } await assignVerificationResult(ctx, provider, { flow, email }); + ctx.status = 204; return next(); } diff --git a/packages/core/src/routes/session/utils.ts b/packages/core/src/routes/session/utils.ts index 629f60d40..a5da486be 100644 --- a/packages/core/src/routes/session/utils.ts +++ b/packages/core/src/routes/session/utils.ts @@ -92,7 +92,9 @@ export const assignVerificationResult = async ( expiresAt: addSeconds(Date.now(), verificationTimeout).toISOString(), }; + const details = await provider.interactionDetails(ctx.req, ctx.res); await provider.interactionResult(ctx.req, ctx.res, { + ...details.result, verification, }); }; @@ -114,7 +116,9 @@ export const assignContinueSignInResult = async ( provider: Provider, payload: { userId: string } ) => { + const details = await provider.interactionDetails(ctx.req, ctx.res); await provider.interactionResult(ctx.req, ctx.res, { + ...details.result, continueSignIn: { ...payload, expiresAt: addSeconds(Date.now(), continueSignInTimeout).toISOString(), diff --git a/packages/schemas/src/types/log.ts b/packages/schemas/src/types/log.ts index 7f1642d43..9bf65948b 100644 --- a/packages/schemas/src/types/log.ts +++ b/packages/schemas/src/types/log.ts @@ -188,6 +188,18 @@ const continueSmsSendPasscodeLogPayloadGuard = arbitraryLogPayloadGuard.and( }) ); +const continueEmailLogPayloadGuard = arbitraryLogPayloadGuard.and( + z.object({ + email: z.string().optional(), + }) +); + +const continueSmsLogPayloadGuard = arbitraryLogPayloadGuard.and( + z.object({ + phone: z.string().optional(), + }) +); + export enum TokenType { AccessToken = 'AccessToken', RefreshToken = 'RefreshToken', @@ -238,6 +250,8 @@ const logPayloadsGuard = z.object({ ForgotPasswordReset: forgotPasswordResetLogPayloadGuard, ContinueEmailSendPasscode: continueEmailSendPasscodeLogPayloadGuard, ContinueSmsSendPasscode: continueSmsSendPasscodeLogPayloadGuard, + ContinueEmail: continueEmailLogPayloadGuard, + ContinueSms: continueSmsLogPayloadGuard, CodeExchangeToken: exchangeTokenLogPayloadGuard, RefreshTokenExchangeToken: exchangeTokenLogPayloadGuard, RevokeToken: revokeTokenLogPayloadGuard,