reset_password_veryify_code
Verify a password reset code and set a new password for AWS Cognito users. Provide username, verification code, and new password to complete the reset process.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| username | Yes | ||
| code | Yes | ||
| newPassword | Yes |
Implementation Reference
- index.ts:343-391 (handler)The handler function for the reset_password_veryify_code tool. It creates a CognitoUser instance and uses confirmPassword to verify the code and set the new password, returning success or error messages.async ({ username, code, newPassword }) => { const cognitoUser = new CognitoUser({ Username: username, Pool: userPool, }); return new Promise((resolve, reject) => { cognitoUser.confirmPassword(code, newPassword, { onSuccess: () => { console.log('Password reset completed'); resolve({ content: [ { type: "text" as const, text: "Password reset successfully", }, { type: "text" as const, text: `Username: ${username}`, }, { type: "text" as const, text: `Verification code: ${code.substr(0, 2)}****${code.substr(-2)}`, }, { type: "text" as const, text: `Password length: ${newPassword.length} characters`, } ] }); }, onFailure: (err) => { console.error('Password reset failed:', err.message); reject({ content: [ { type: "text" as const, text: `Password reset failed: ${err.message}`, }, { type: "text" as const, text: `Error code: ${(err as any).code || 'Unknown'}`, } ] }); } }); }); }
- index.ts:338-342 (schema)Zod schema defining the input parameters: username, code, and newPassword.{ username: z.string(), code: z.string(), newPassword: z.string(), },
- index.ts:336-392 (registration)Registration of the reset_password_veryify_code tool using server.tool, including name, schema, and handler.server.tool( "reset_password_veryify_code", { username: z.string(), code: z.string(), newPassword: z.string(), }, async ({ username, code, newPassword }) => { const cognitoUser = new CognitoUser({ Username: username, Pool: userPool, }); return new Promise((resolve, reject) => { cognitoUser.confirmPassword(code, newPassword, { onSuccess: () => { console.log('Password reset completed'); resolve({ content: [ { type: "text" as const, text: "Password reset successfully", }, { type: "text" as const, text: `Username: ${username}`, }, { type: "text" as const, text: `Verification code: ${code.substr(0, 2)}****${code.substr(-2)}`, }, { type: "text" as const, text: `Password length: ${newPassword.length} characters`, } ] }); }, onFailure: (err) => { console.error('Password reset failed:', err.message); reject({ content: [ { type: "text" as const, text: `Password reset failed: ${err.message}`, }, { type: "text" as const, text: `Error code: ${(err as any).code || 'Unknown'}`, } ] }); } }); }); } )