Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/hungry-ties-bet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@asgardeo/javascript': patch
---

Refactor embedded sign-in and sign-up flows: clean payload by removing 'verbose' parameter and conditionally add
'verbose: true' based on payload structure.
23 changes: 22 additions & 1 deletion packages/javascript/src/api/v2/executeEmbeddedSignInFlowV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,30 @@ const executeEmbeddedSignInFlowV2 = async ({

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

// Strip any user-provided 'verbose' parameter as it should only be used internally
const cleanPayload: typeof payload =
typeof payload === 'object' && payload !== null
? Object.fromEntries(Object.entries(payload).filter(([key]) => key !== 'verbose'))
: payload;

// `verbose: true` is required to get the `meta` field in the response that includes component details.
// Add verbose:true if:
// 1. payload contains only applicationId and flowType
// 2. payload contains only flowId
const hasOnlyAppIdAndFlowType: boolean =
typeof cleanPayload === 'object' &&
cleanPayload !== null &&
'applicationId' in cleanPayload &&
'flowType' in cleanPayload &&
Object.keys(cleanPayload).length === 2;
const hasOnlyFlowId: boolean =
typeof cleanPayload === 'object' &&
cleanPayload !== null &&
'flowId' in cleanPayload &&
Object.keys(cleanPayload).length === 1;

const requestPayload: Record<string, unknown> =
typeof payload === 'object' && payload !== null && 'flowType' in payload ? {...payload, verbose: true} : payload;
hasOnlyAppIdAndFlowType || hasOnlyFlowId ? {...cleanPayload, verbose: true} : cleanPayload;

const response: Response = await fetch(endpoint, {
...requestConfig,
Expand Down
23 changes: 22 additions & 1 deletion packages/javascript/src/api/v2/executeEmbeddedSignUpFlowV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,30 @@ const executeEmbeddedSignUpFlowV2 = async ({

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

// Strip any user-provided 'verbose' parameter as it should only be used internally
const cleanPayload: typeof payload =
typeof payload === 'object' && payload !== null
? Object.fromEntries(Object.entries(payload).filter(([key]) => key !== 'verbose'))
: payload;

// `verbose: true` is required to get the `meta` field in the response that includes component details.
// Add verbose:true if:
// 1. payload contains only applicationId and flowType
// 2. payload contains only flowId
const hasOnlyAppIdAndFlowType: boolean =
typeof cleanPayload === 'object' &&
cleanPayload !== null &&
'applicationId' in cleanPayload &&
'flowType' in cleanPayload &&
Object.keys(cleanPayload).length === 2;
const hasOnlyFlowId: boolean =
typeof cleanPayload === 'object' &&
cleanPayload !== null &&
'flowId' in cleanPayload &&
Object.keys(cleanPayload).length === 1;

const requestPayload: Record<string, unknown> =
typeof payload === 'object' && payload !== null && 'flowType' in payload ? {...payload, verbose: true} : payload;
hasOnlyAppIdAndFlowType || hasOnlyFlowId ? {...cleanPayload, verbose: true} : cleanPayload;

const response: Response = await fetch(endpoint, {
...requestConfig,
Expand Down
Loading