Skip to content

Commit

Permalink
fix: email handler not working
Browse files Browse the repository at this point in the history
  • Loading branch information
Miodec committed Feb 22, 2024
1 parent 67f0df7 commit 2db6a88
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions frontend/src/email-handler.html
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,14 @@
</body>
<script type="module">
import $ from "jquery";
import { app as firebase } from "./ts/firebase";
import { Auth } from "./ts/firebase";
import {
applyActionCode,
verifyPasswordResetCode,
confirmPasswordReset,
checkActionCode,
sendPasswordResetEmail,
} from "firebase/auth";

function isPasswordStrong(password) {
const hasCapital = !!password.match(/[A-Z]/);
Expand All @@ -178,9 +185,7 @@
}

function handleVerifyEmail(actionCode, continueUrl) {
firebase
.auth()
.applyActionCode(actionCode)
applyActionCode(Auth, actionCode)
.then((resp) => {
// Email address has been verified.

Expand Down Expand Up @@ -213,9 +218,7 @@
function handleResetPassword(actionCode, continueUrl) {
// Verify the password reset code is valid.
hideResetPassword();
firebase
.auth()
.verifyPasswordResetCode(actionCode)
verifyPasswordResetCode(Auth, actionCode)
.then((email) => {
var accountEmail = email;

Expand All @@ -237,9 +240,7 @@
}

// Save the new password.
firebase
.auth()
.confirmPasswordReset(actionCode, newPassword)
confirmPasswordReset(Auth, actionCode, newPassword)
.then((resp) => {
// Password reset has been confirmed and new password updated.
$("main .preloader .icon").html(
Expand Down Expand Up @@ -276,15 +277,13 @@
// parameter.
var restoredEmail = null;
// Confirm the action code is valid.
firebase
.auth()
.checkActionCode(actionCode)
checkActionCode(Auth, actionCode)
.then((info) => {
// Get the restored email address.
restoredEmail = info["data"]["email"];

// Revert to the old email.
return auth.applyActionCode(actionCode);
return applyActionCode(Auth, actionCode);
})
.then(() => {
$("main .preloader .icon").html(`<i class="fas fa-fw fa-check"></i>`);
Expand All @@ -297,7 +296,7 @@
`);
$("main .preloader").append(`
<br>
<div class="button" onclick="sendPasswordResetEmail('${restoredEmail}')">Send Password Reset Email</div>
<div class="button" onclick="sendPasswordReset('${restoredEmail}')">Send Password Reset Email</div>
`);

// Account email reverted to restoredEmail
Expand All @@ -313,9 +312,8 @@
});
}

function sendPasswordResetEmail(email) {
auth
.sendPasswordResetEmail(email)
function sendPasswordReset(email) {
sendPasswordResetEmail(Auth, email)
.then(() => {
$("main .preloader .icon").html(`<i class="fas fa-fw fa-check"></i>`);
$("main .preloader .text").text(`Password reset email sent`);
Expand Down

0 comments on commit 2db6a88

Please sign in to comment.