Home > Blockchain >  get user email from firebase auth
get user email from firebase auth

Time:10-13

I want to display the user email as a string from my auth variable. In the first image below, I declare the auth variable. The second image is what I get when I console.log(auth). How do I get the user email and other info? I tried various combinations of console.logs and mostly get null.

enter image description here

enter image description here

CodePudding user response:

Firebase's documentation has a section called "Get a user's profile" that explains the same. Try the following:

import { getAuth, onAuthStateChanged } from "firebase/auth";

const auth = getAuth();

onAuthStateChanged(auth, (user) => {
  if (user) {
    const email = user.email;
    console.log(email)
  } else {
    console.log("User not logged in")
  }
})
  • Related