diff --git a/packages/core/src/routes/interaction/index.ts b/packages/core/src/routes/interaction/index.ts index ab35a3160..61c884e0b 100644 --- a/packages/core/src/routes/interaction/index.ts +++ b/packages/core/src/routes/interaction/index.ts @@ -88,16 +88,16 @@ export default function interactionRoutes( verifyProfileSettings(profile, signInExperience); } - const verifiedIdentifier = identifier && [ + const verifiedIdentifiers = identifier && [ await verifyIdentifierPayload(ctx, tenant, identifier, { event, }), ]; - eventLog.append({ profile, verifiedIdentifier }); + eventLog.append({ profile, verifiedIdentifiers }); await storeInteractionResult( - { event, identifiers: verifiedIdentifier, profile }, + { event, identifiers: verifiedIdentifiers, profile }, ctx, provider ); diff --git a/packages/core/src/routes/interaction/types/guard.ts b/packages/core/src/routes/interaction/types/guard.ts index 664c683b2..57f52d9aa 100644 --- a/packages/core/src/routes/interaction/types/guard.ts +++ b/packages/core/src/routes/interaction/types/guard.ts @@ -1,6 +1,6 @@ import { socialUserInfoGuard } from '@logto/connector-kit'; import { validateRedirectUrl } from '@logto/core-kit'; -import { eventGuard, profileGuard, InteractionEvent } from '@logto/schemas'; +import { eventGuard, profileGuard } from '@logto/schemas'; import { z } from 'zod'; // Social Authorization Uri Route Payload Guard @@ -46,26 +46,6 @@ export const anonymousInteractionResultGuard = z.object({ identifiers: z.array(identifierGuard).optional(), }); -export const verifiedRegisterInteractionResultGuard = z.object({ - event: z.literal(InteractionEvent.Register), - profile: profileGuard.optional(), - identifiers: z.array(identifierGuard).optional(), -}); - -export const verifiedSignInteractionResultGuard = z.object({ - event: z.literal(InteractionEvent.SignIn), - accountId: z.string(), - profile: profileGuard.optional(), - identifiers: z.array(identifierGuard), -}); - export const forgotPasswordProfileGuard = z.object({ password: z.string(), }); - -export const verifiedForgotPasswordInteractionResultGuard = z.object({ - event: z.literal(InteractionEvent.ForgotPassword), - accountId: z.string(), - identifiers: z.array(identifierGuard), - profile: forgotPasswordProfileGuard, -}); diff --git a/packages/core/src/routes/interaction/types/index.ts b/packages/core/src/routes/interaction/types/index.ts index be87c3202..7fd92d561 100644 --- a/packages/core/src/routes/interaction/types/index.ts +++ b/packages/core/src/routes/interaction/types/index.ts @@ -6,6 +6,7 @@ import type { InteractionEvent, SocialEmailPayload, SocialPhonePayload, + Profile, } from '@logto/schemas'; import type { z } from 'zod'; @@ -17,9 +18,6 @@ import type { socialIdentifierGuard, identifierGuard, anonymousInteractionResultGuard, - verifiedRegisterInteractionResultGuard, - verifiedSignInteractionResultGuard, - verifiedForgotPasswordInteractionResultGuard, } from './guard.js'; /* Payload Types */ @@ -44,7 +42,7 @@ export type SocialIdentifier = z.infer; export type Identifier = z.infer; -// Interaction +// Interaction Result export type AnonymousInteractionResult = z.infer; export type RegisterInteractionResult = Omit & { @@ -59,6 +57,7 @@ export type ForgotPasswordInteractionResult = Omit & { accountId: string; @@ -73,15 +72,27 @@ export type IdentifierVerifiedInteractionResult = | RegisterInteractionResult | AccountVerifiedInteractionResult; -export type VerifiedRegisterInteractionResult = z.infer< - typeof verifiedRegisterInteractionResultGuard ->; +export type VerifiedRegisterInteractionResult = { + event: InteractionEvent.Register; + profile?: Profile; + identifiers?: Identifier[]; +}; -export type VerifiedSignInInteractionResult = z.infer; +export type VerifiedSignInInteractionResult = { + event: InteractionEvent.SignIn; + accountId: string; + identifiers: Identifier[]; + profile?: Profile; +}; -export type VerifiedForgotPasswordInteractionResult = z.infer< - typeof verifiedForgotPasswordInteractionResultGuard ->; +export type VerifiedForgotPasswordInteractionResult = { + event: InteractionEvent.ForgotPassword; + accountId: string; + identifiers: Identifier[]; + profile: { + password: string; + }; +}; export type VerifiedInteractionResult = | VerifiedRegisterInteractionResult diff --git a/packages/schemas/src/types/interactions.ts b/packages/schemas/src/types/interactions.ts index c5e356f9c..6da992c90 100644 --- a/packages/schemas/src/types/interactions.ts +++ b/packages/schemas/src/types/interactions.ts @@ -13,9 +13,8 @@ import { } from './verification-code.js'; /** - * Detailed Identifier Methods guard + * Detailed interaction identifier payload guard */ - export const usernamePasswordPayloadGuard = z.object({ username: z.string().min(1), password: z.string().min(1), @@ -54,9 +53,7 @@ export const socialPhonePayloadGuard = z.object({ export type SocialPhonePayload = z.infer; -// Interaction Payload Guard - -/** Interaction flow (main flow) types. */ +// Interaction flow event types export enum InteractionEvent { SignIn = 'SignIn', Register = 'Register',