Right now I am doing the following:
function resetPassword(email) {
/* The following is for the alert dialog box that is triggered when the user
presses forget password! */
Swal.fire({
title: 'Enter the email address',
input: 'text',
inputAttributes: {
autocapitalize: 'off'
},
showCancelButton: true,
confirmButtonText: 'Send Reset Email',
}).then((input) => {
firebase.auth().sendPasswordResetEmail(email)
.then(() => {
Swal.fire({
title: 'Email Sent!',
text: 'Check your email for a reset link!',
type: 'success',
confirmButtonText: 'Cool'
});
})
.catch((error) => {
Swal.fire({
title: 'Error!',
text: error.message,
type: 'error',
confirmButtonText: 'Cool'
});
});
});
}
But it is not working, what am I doing wrong?
My main outcome is to get the email, pass it through to firebase auth api, send the email, then put one more diag box out that says "done" basically. But the input is not coming through. Why is this?
Thanks in advance.
The Swal result will be stored in an object with the same name that you define in the passed parameter to the 'then' function, in this case, input. The email address is stored in input.value. I'd also remove the unnecessary email parameter from the function declaration. This should work:
function resetPassword() {
/* The following is for the alert dialog box that is triggered when the user
presses forget password! */
Swal.fire({
title: 'Enter the email address',
input: 'text',
inputAttributes: {
autocapitalize: 'off'
},
showCancelButton: true,
confirmButtonText: 'Send Reset Email',
}).then(({value: input}) => {
firebase.auth().sendPasswordResetEmail(input)
.then(() => {
Swal.fire({
title: 'Email Sent!',
text: 'Check your email for a reset link!',
type: 'success',
confirmButtonText: 'Cool'
});
})
.catch((error) => {
Swal.fire({
title: 'Error!',
text: error.message,
type: 'error',
confirmButtonText: 'Cool'
});
});
});
}
Thank you for your answer @Chris, but after yours not working I then went onto the SA2 docs and found a login page, then heavily modified it to the following:
function resetPassword() {
/* The following is for the alert dialog box that is triggered when the user
presses forget password! */
Swal.fire({
title: 'Please Enter Your Email Address',
html: `<input type="text" id="email" class="swal2-input" placeholder="mail@website.com">`,
confirmButtonText: 'Sign in',
focusConfirm: false,
preConfirm: () => {
const email = Swal.getPopup().querySelector('#email').value
return { email: email }
}
}).then((result) => {
firebase.auth().sendPasswordResetEmail(result.value.email)
.then(() => {
Swal.fire({
icon: 'success',
title: 'Email Sent!',
text: 'Check your email for a reset link!',
type: 'success',
confirmButtonText: 'Cool'
});
})
.catch((error) => {
Swal.fire({
title: 'Error!',
text: error.message,
type: 'error',
confirmButtonText: 'Cool'
});
});
});
}
Thanks for your help though and the solution which I am posting now did take a long time to make so you are still greatly appreciated.
Have a nice day!