Firestore won't add signup email to new database collection

家住魔仙堡 提交于 2020-06-29 03:39:26

问题


When signing up a user, I get no error what so ever, the signup works, but it doesn't create a new DB collection with the signup email.

Furthermore, redirecting the user to /account/dashboard.html doesn't work.

Any ideas? I am very new to all of this, only 4 days in so if you could please explain things a little simpler to me that would be very much appreciated.

// sign up the user
    firebase.auth().createUserWithEmailAndPassword(email, password).then(cred => {
        return db.collection('users').doc(cred.user.uid).set({
            email: "signupForm['signupEmail'].value"
        });
    }).then(function() {
            window.location.replace('/account/dashboard.html');
        })
        .catch(function (error) {
            var errorCode = error.code;
            var errorMessage = error.message;
            console.log('Error code: ' + errorCode);
            console.log('Error message: ' + errorMessage);
            signupButton.style.display = 'flex';
            signupError.innerText = errorMessage;
            signupError.style.display = 'flex';
            signupForm.reset();
        });
})

    // Trigger button click on enter
    var input = document.getElementById("signupPasswordConfirm");

    // Execute a function when the user releases a key on the keyboard
    input.addEventListener("keyup", function(event) {
    // Number 13 is the "Enter" key on the keyboard
    if (event.keyCode === 13) {
        // Trigger the button element with a click
        document.getElementById("signupButton").click();
    }
});

My HTML

<div class="form-content"><label for="signupPassword-2" id="signupError" class="error-message">Error message</label>
        <div class="form-wrap extra-space"><input type="text" class="text-field w-input" maxlength="256" name="signupEmail" data-name="signupEmail" placeholder="E-mail" id="signupEmail"></div>
        <div class="form-wrap extra-space"><input type="password" class="text-field w-input" maxlength="256" name="signupPassword" data-name="signupPassword" placeholder="Password" id="signupPassword"></div>
        <div class="form-wrap extra-space"><input type="password" class="text-field w-input" maxlength="256" name="signupPasswordConfirm" data-name="signupPasswordConfirm" placeholder="Confirm your Password" id="signupPasswordConfirm"></div>
        <div class="button-wrap"><a id="signupButton" href="#" class="button w-button">Signup</a>
          <h5 class="h5 black centered">Already have an account?</h5>
        </div>

回答1:


Turns out I forgot to declare the DB variable. Also changed the output of email:

// sign up the user
    const db = firebase.firestore();
    firebase.auth().createUserWithEmailAndPassword(email, password).then(cred => {
        return db.collection('users').doc(cred.user.uid).set({
            email: signupForm['signupEmail'].value
        });


来源:https://stackoverflow.com/questions/62598411/firestore-wont-add-signup-email-to-new-database-collection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!