nuxt-community / firebase-module

🔥 Easily integrate Firebase into your Nuxt project. 🔥
https://firebase.nuxtjs.org
MIT License
641 stars 98 forks source link

how to change and listen user email/password/emailVerified directly? #378

Closed szczynk closed 3 years ago

szczynk commented 3 years ago

Hello, i tried update email using this.$fireAuth.currentUser.updateEmail(this.newEmail) but did not change directly, it need to be refresh page.

Based on this documentation, it is only triggered on sign-in, sign-out, or in my case, refresh page.

Is there any option that change onAuthStateChanged() function to be onIdTokenChanged() function when generate .nuxt/firebase-module/initAuth.js so i can change and listen user email/password/emailVerified directly?

i'm so sorry if my english is broken thank you very much

lupas commented 3 years ago

Hey @szczynk Updated auth user data does not get automatically pushed to the client and does not trigger "onAuthStateChanged", because the auth state itself has not changed. You can do the following to refresh the auth user on your client:

 try {
        await this.$fire.auth.currentUser.updateEmail('newEmail@email.com')
        // Reload the user
        this.$fire.auth.currentUser.reload()
        // Now you can get the updated user like so
        const updatedUser = this.$fire.auth.currentUser
        // And then manually save the infos to the vuex store or wherever you like
      } catch (e) {
        console.error(e)
      }

Btw: $this.fire.auth is syntax for module v7.0.0+, make sure to update to the newest version :)

szczynk commented 3 years ago

thank you so much for the alternative @lupas :+1: i will try migrate from v6 to v7 :)