1

I have a problem editing the 'email' field. When I click change mail, the email changes correctly, but when I want to log in again, the new email is not working, only the old one is still working. How to do it so that after clicking on change email it will change in the database so that after logging in again the new email will work. I do not know how to do this. I have this code.

<template>
    <div class="editemail">
        <div class="container">
            <form class="form" @submit.prevent>
                <!-- email -->
                <label for="email" class="form__label">Email</label>
                <input
                    class="form__input"
                    type="text"
                    id="email"
                    name="email"
                    :placeholder="userProfile.email"
                    v-model.trim="email"
                />

                <button class="form__button" type="submit" @click="editEmail()">
                    Zmień email
                </button>
            </form>
        </div>
    </div>
</template>

<script>
import { mapState } from 'vuex';
import * as firebase from '../firebase';

export default {
    data() {
        return {
            email: '',
        };
    },

    computed: {
        ...mapState(['userProfile']),
    },

    methods: {
        editEmail() {
            firebase.usersCollection.doc(firebase.auth.currentUser.uid).update({
                email: this.email,
            });
        },
    },
};
</script>

1 Answer 1

1

If you're using Firebase Authentication to sign the user in, then the email address that it uses has nothing to do with the value you store in the database.

To update the email address that Firebase uses to sign in, you'll also want to call firebase.auth().currentUser.updateEmail(this.email) to update the user's email address.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.