Skip to content

Commit 1bac245

Browse files
authored
Merge pull request #289 from brionmario/refactor-thunder-flows
Fix `verbose: true` not sending when only `flowId` is present
2 parents a4bfc30 + 149bf46 commit 1bac245

File tree

3 files changed

+50
-2
lines changed

3 files changed

+50
-2
lines changed

.changeset/hungry-ties-bet.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@asgardeo/javascript': patch
3+
---
4+
5+
Refactor embedded sign-in and sign-up flows: clean payload by removing 'verbose' parameter and conditionally add
6+
'verbose: true' based on payload structure.

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)