Damian Sierocki
Damian Sierocki

Reputation: 55

Edit Email firestore vue

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>

Upvotes: 1

Views: 77

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 599571

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.

Upvotes: 1

Related Questions