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.
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")
}
})