Create a session for a user by entering a username and password. If the user
requires a password reset, the "resetPasswordCallback" property will be
returned. This function should be called with the new password once entered
by the user. If the user requires an MFA token, the "mfa" property will be
returned. Its "codeCallback" should be called with the one-time token. The
functions returned are recursive and the result from each of them is the same
result from the loginUsernamePassword() function. Each time the response
includes a callback, you will need to begin the process again until all
callbacks are handled.
Example
asyncfunctionhandleLoginAttemptResponse({ resetPasswordCallback, mfa, }) { // "resetPasswordCallback" will be undefined if a password reset was not required. if (resetPasswordCallback) { // Prompt the user to enter a new password constnewPassword = prompt( 'The password you entered was only temporary, and must be reset for security purposes. Please enter your new password below to continue.', ) constresetPasswordResponse = awaitresetPasswordCallback(newPassword) returnawaithandleLoginAttemptResponse(resetPasswordResponse) }
// "mfa" will be undefined if MFA is not setup. if (mfa) { // Prompt the user to enter an MFA code constcode = prompt( mfa.method === 'email' ? 'Please enter the one-time code sent to your email.' : 'Please enter a one-time code from your MFA app.', ) constmfaCodeResponse = awaitmfa.codeCallback(code) returnawaithandleLoginAttemptResponse(mfaCodeResponse) } }
Create a session for a user by entering a username and password. If the user requires a password reset, the "resetPasswordCallback" property will be returned. This function should be called with the new password once entered by the user. If the user requires an MFA token, the "mfa" property will be returned. Its "codeCallback" should be called with the one-time token. The functions returned are recursive and the result from each of them is the same result from the loginUsernamePassword() function. Each time the response includes a callback, you will need to begin the process again until all callbacks are handled.
Example