From 16c7246b2bb494f7f5df98b0d13641a902445076 Mon Sep 17 00:00:00 2001 From: Ken'ichiro Oyama Date: Thu, 2 Jul 2026 10:03:47 +0900 Subject: [PATCH 1/2] docs(function): return results directly in managing-idp-users samples MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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/guides/function/managing-idp-users.md | 26 +++++----------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/docs/guides/function/managing-idp-users.md b/docs/guides/function/managing-idp-users.md index 53a774b..0e2c087 100644 --- a/docs/guides/function/managing-idp-users.md +++ b/docs/guides/function/managing-idp-users.md @@ -214,7 +214,6 @@ export default async (args) => { }); return { - success: true, userId: newUser.id, userName: newUser.name, }; @@ -238,7 +237,6 @@ export default async (args) => { }); return { - success: true, userId: newUser.id, userName: newUser.name, }; @@ -264,7 +262,6 @@ export default async (args) => { }); return { - success: true, userId: updatedUser.id, disabled: updatedUser.disabled, }; @@ -283,7 +280,6 @@ export default async (args) => { }); return { - success: true, userId: updatedUser.id, }; }; @@ -297,11 +293,7 @@ The `deleteUser` method deletes a user by their ID. export default async (args) => { const idpClient = new tailor.idp.Client({ namespace: args.namespaceName }); - const success = await idpClient.deleteUser(args.userId); - - return { - success: success, - }; + return await idpClient.deleteUser(args.userId); }; ``` @@ -313,16 +305,12 @@ The `sendPasswordResetEmail` method sends a password reset email to a user. This export default async (args) => { const idpClient = new tailor.idp.Client({ namespace: args.namespaceName }); - const success = await idpClient.sendPasswordResetEmail({ + return await idpClient.sendPasswordResetEmail({ userId: args.userId, redirectUri: "https://your-app.com/reset-password-complete", fromName: "My App Support", subject: "Password Reset for Your My App Account", }); - - return { - success: success, - }; }; ``` @@ -346,11 +334,10 @@ To remove one specific factor: ```js export default async (args) => { const idpClient = new tailor.idp.Client({ namespace: args.namespaceName }); - const success = await idpClient.unenrollMfa({ + return await idpClient.unenrollMfa({ userId: args.userId, mfaFactorId: args.mfaFactorId, }); - return { success }; }; ``` @@ -361,17 +348,14 @@ export default async (args) => { const idpClient = new tailor.idp.Client({ namespace: args.namespaceName }); const user = await idpClient.user(args.userId); - if (!user.mfaEnrolled) { - return { success: false, reason: "User has no enrolled MFA factors" }; - } - const results = await Promise.all( + await Promise.all( user.mfaFactorIds.map((mfaFactorId) => idpClient.unenrollMfa({ userId: user.id, mfaFactorId }), ), ); - return { success: results.every(Boolean) }; + return { unenrolledFactorIds: user.mfaFactorIds }; }; ``` From 68b091d6a454691818fdfcb6c4a54c234a6e993c Mon Sep 17 00:00:00 2001 From: Ken'ichiro Oyama Date: Thu, 2 Jul 2026 13:37:22 +0900 Subject: [PATCH 2/2] 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. --- docs/guides/function/managing-idp-users.md | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/docs/guides/function/managing-idp-users.md b/docs/guides/function/managing-idp-users.md index 0e2c087..d605ad2 100644 --- a/docs/guides/function/managing-idp-users.md +++ b/docs/guides/function/managing-idp-users.md @@ -293,7 +293,7 @@ The `deleteUser` method deletes a user by their ID. export default async (args) => { const idpClient = new tailor.idp.Client({ namespace: args.namespaceName }); - return await idpClient.deleteUser(args.userId); + return idpClient.deleteUser(args.userId); }; ``` @@ -305,7 +305,7 @@ The `sendPasswordResetEmail` method sends a password reset email to a user. This export default async (args) => { const idpClient = new tailor.idp.Client({ namespace: args.namespaceName }); - return await idpClient.sendPasswordResetEmail({ + return idpClient.sendPasswordResetEmail({ userId: args.userId, redirectUri: "https://your-app.com/reset-password-complete", fromName: "My App Support", @@ -334,7 +334,7 @@ To remove one specific factor: ```js export default async (args) => { const idpClient = new tailor.idp.Client({ namespace: args.namespaceName }); - return await idpClient.unenrollMfa({ + return idpClient.unenrollMfa({ userId: args.userId, mfaFactorId: args.mfaFactorId, }); @@ -349,13 +349,17 @@ export default async (args) => { const user = await idpClient.user(args.userId); - await Promise.all( + const results = await Promise.all( user.mfaFactorIds.map((mfaFactorId) => idpClient.unenrollMfa({ userId: user.id, mfaFactorId }), ), ); - return { unenrolledFactorIds: user.mfaFactorIds }; + const unenrolledFactorIds = user.mfaFactorIds.filter( + (_, index) => results[index], + ); + + return { unenrolledFactorIds }; }; ```