Skip to content

Commit 866c2f0

Browse files
committed
Refactor embedded sign-in and sign-up flows: clean payload by removing 'verbose' parameter and conditionally add 'verbose: true' based on payload structure.
1 parent d02af44 commit 866c2f0

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

packages/javascript/src/api/v2/executeEmbeddedSignInFlowV2.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,30 @@ const executeEmbeddedSignInFlowV2 = async ({
4242

4343
let endpoint: string = url ?? `${baseUrl}/flow/execute`;
4444

45+
// Strip any user-provided 'verbose' parameter as it should only be used internally
46+
const cleanPayload: typeof payload =
47+
typeof payload === 'object' && payload !== null
48+
? Object.fromEntries(Object.entries(payload).filter(([key]) => key !== 'verbose'))
49+
: payload;
50+
4551
// `verbose: true` is required to get the `meta` field in the response that includes component details.
52+
// Add verbose:true if:
53+
// 1. payload contains only applicationId and flowType
54+
// 2. payload contains only flowId
55+
const hasOnlyAppIdAndFlowType: boolean =
56+
typeof cleanPayload === 'object' &&
57+
cleanPayload !== null &&
58+
'applicationId' in cleanPayload &&
59+
'flowType' in cleanPayload &&
60+
Object.keys(cleanPayload).length === 2;
61+
const hasOnlyFlowId: boolean =
62+
typeof cleanPayload === 'object' &&
63+
cleanPayload !== null &&
64+
'flowId' in cleanPayload &&
65+
Object.keys(cleanPayload).length === 1;
66+
4667
const requestPayload: Record<string, unknown> =
47-
typeof payload === 'object' && payload !== null && 'flowType' in payload ? {...payload, verbose: true} : payload;
68+
hasOnlyAppIdAndFlowType || hasOnlyFlowId ? {...cleanPayload, verbose: true} : cleanPayload;
4869

4970
const response: Response = await fetch(endpoint, {
5071
...requestConfig,

packages/javascript/src/api/v2/executeEmbeddedSignUpFlowV2.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,30 @@ const executeEmbeddedSignUpFlowV2 = async ({
4242

4343
let endpoint: string = url ?? `${baseUrl}/flow/execute`;
4444

45+
// Strip any user-provided 'verbose' parameter as it should only be used internally
46+
const cleanPayload: typeof payload =
47+
typeof payload === 'object' && payload !== null
48+
? Object.fromEntries(Object.entries(payload).filter(([key]) => key !== 'verbose'))
49+
: payload;
50+
4551
// `verbose: true` is required to get the `meta` field in the response that includes component details.
52+
// Add verbose:true if:
53+
// 1. payload contains only applicationId and flowType
54+
// 2. payload contains only flowId
55+
const hasOnlyAppIdAndFlowType: boolean =
56+
typeof cleanPayload === 'object' &&
57+
cleanPayload !== null &&
58+
'applicationId' in cleanPayload &&
59+
'flowType' in cleanPayload &&
60+
Object.keys(cleanPayload).length === 2;
61+
const hasOnlyFlowId: boolean =
62+
typeof cleanPayload === 'object' &&
63+
cleanPayload !== null &&
64+
'flowId' in cleanPayload &&
65+
Object.keys(cleanPayload).length === 1;
66+
4667
const requestPayload: Record<string, unknown> =
47-
typeof payload === 'object' && payload !== null && 'flowType' in payload ? {...payload, verbose: true} : payload;
68+
hasOnlyAppIdAndFlowType || hasOnlyFlowId ? {...cleanPayload, verbose: true} : cleanPayload;
4869

4970
const response: Response = await fetch(endpoint, {
5071
...requestConfig,

0 commit comments

Comments
 (0)