0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-30 20:33:54 -05:00

refactor(core): clean up useless interaction guard (#4409)

refactor(core): clean up unused interaction guards

clean up unused interaction guards
This commit is contained in:
simeng-li 2023-09-04 10:55:04 +08:00 committed by GitHub
parent ac859afec9
commit 8607b3eb75
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 40 deletions

View file

@ -88,16 +88,16 @@ export default function interactionRoutes<T extends AnonymousRouter>(
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
);

View file

@ -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,
});

View file

@ -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<typeof socialIdentifierGuard>;
export type Identifier = z.infer<typeof identifierGuard>;
// Interaction
// Interaction Result
export type AnonymousInteractionResult = z.infer<typeof anonymousInteractionResultGuard>;
export type RegisterInteractionResult = Omit<AnonymousInteractionResult, 'event'> & {
@ -59,6 +57,7 @@ export type ForgotPasswordInteractionResult = Omit<AnonymousInteractionResult, '
event: InteractionEvent.ForgotPassword;
};
// Intermediate interaction result
export type AccountVerifiedInteractionResult =
| (Omit<SignInInteractionResult, 'accountId' | 'identifiers'> & {
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<typeof verifiedSignInteractionResultGuard>;
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

View file

@ -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<typeof socialPhonePayloadGuard>;
// Interaction Payload Guard
/** Interaction flow (main flow) types. */
// Interaction flow event types
export enum InteractionEvent {
SignIn = 'SignIn',
Register = 'Register',