Skip to content

Commit a320459

Browse files
authored
docs(function): return results directly in managing-idp-users samples (#156)
* docs(function): return results directly in managing-idp-users samples The `tailor.idp` client methods reject on failure, so wrapping their results in a `{ success }` object made the samples read as if they presuppose try/catch-based error handling — and implicitly recommended returning a result object. Return the meaningful value directly and let errors propagate as thrown exceptions, so the samples reflect the recommended "throw unless you need to control the error or its message" style rather than a success/error result object. * docs(function): drop redundant return await and report only unenrolled factors Apply Copilot review feedback on the managing-idp-users samples. - Drop the redundant `await` from the `deleteUser`, `sendPasswordResetEmail`, and single-factor `unenrollMfa` samples. With no surrounding `try`/`catch`, returning the promise directly is equivalent and reads more simply. - In the reset-all-MFA sample, filter `user.mfaFactorIds` by the boolean results of `unenrollMfa()` so `unenrolledFactorIds` reflects the factors that were actually unenrolled, rather than assuming every factor succeeded.
1 parent 82a8b0f commit a320459

1 file changed

Lines changed: 8 additions & 20 deletions

File tree

docs/guides/function/managing-idp-users.md

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,6 @@ export default async (args) => {
214214
});
215215

216216
return {
217-
success: true,
218217
userId: newUser.id,
219218
userName: newUser.name,
220219
};
@@ -238,7 +237,6 @@ export default async (args) => {
238237
});
239238

240239
return {
241-
success: true,
242240
userId: newUser.id,
243241
userName: newUser.name,
244242
};
@@ -264,7 +262,6 @@ export default async (args) => {
264262
});
265263

266264
return {
267-
success: true,
268265
userId: updatedUser.id,
269266
disabled: updatedUser.disabled,
270267
};
@@ -283,7 +280,6 @@ export default async (args) => {
283280
});
284281

285282
return {
286-
success: true,
287283
userId: updatedUser.id,
288284
};
289285
};
@@ -297,11 +293,7 @@ The `deleteUser` method deletes a user by their ID.
297293
export default async (args) => {
298294
const idpClient = new tailor.idp.Client({ namespace: args.namespaceName });
299295

300-
const success = await idpClient.deleteUser(args.userId);
301-
302-
return {
303-
success: success,
304-
};
296+
return idpClient.deleteUser(args.userId);
305297
};
306298
```
307299

@@ -313,16 +305,12 @@ The `sendPasswordResetEmail` method sends a password reset email to a user. This
313305
export default async (args) => {
314306
const idpClient = new tailor.idp.Client({ namespace: args.namespaceName });
315307

316-
const success = await idpClient.sendPasswordResetEmail({
308+
return idpClient.sendPasswordResetEmail({
317309
userId: args.userId,
318310
redirectUri: "https://your-app.com/reset-password-complete",
319311
fromName: "My App Support",
320312
subject: "Password Reset for Your My App Account",
321313
});
322-
323-
return {
324-
success: success,
325-
};
326314
};
327315
```
328316

@@ -346,11 +334,10 @@ To remove one specific factor:
346334
```js
347335
export default async (args) => {
348336
const idpClient = new tailor.idp.Client({ namespace: args.namespaceName });
349-
const success = await idpClient.unenrollMfa({
337+
return idpClient.unenrollMfa({
350338
userId: args.userId,
351339
mfaFactorId: args.mfaFactorId,
352340
});
353-
return { success };
354341
};
355342
```
356343

@@ -361,17 +348,18 @@ export default async (args) => {
361348
const idpClient = new tailor.idp.Client({ namespace: args.namespaceName });
362349

363350
const user = await idpClient.user(args.userId);
364-
if (!user.mfaEnrolled) {
365-
return { success: false, reason: "User has no enrolled MFA factors" };
366-
}
367351

368352
const results = await Promise.all(
369353
user.mfaFactorIds.map((mfaFactorId) =>
370354
idpClient.unenrollMfa({ userId: user.id, mfaFactorId }),
371355
),
372356
);
373357

374-
return { success: results.every(Boolean) };
358+
const unenrolledFactorIds = user.mfaFactorIds.filter(
359+
(_, index) => results[index],
360+
);
361+
362+
return { unenrolledFactorIds };
375363
};
376364
```
377365

0 commit comments

Comments
 (0)