Complete the code to initialize Firebase Authentication.
const auth = firebase.[1]();The auth() function returns the Firebase Authentication instance.
Complete the code to sign in a user with email and password.
firebase.auth().signInWithEmailAndPassword([1], password);The signInWithEmailAndPassword method requires the user's email as the first argument.
Fix the error in the code to get the current authenticated user.
const user = firebase.auth().[1];The currentUser is a property, not a function, so it should not have parentheses.
Fill both blanks to listen for authentication state changes.
firebase.auth().[1]((user) => { if (user) { console.log('User is [2]'); } });
The method to listen for auth changes is onAuthStateChanged. When a user is signed in, the callback receives the user object.
Fill all three blanks to create a new user with email and password and handle errors.
firebase.auth().createUserWithEmailAndPassword([1], [2]) .then((userCredential) => { const user = userCredential.[3]; console.log('User created:', user.email); }) .catch((error) => { console.error(error.message); });
The createUserWithEmailAndPassword method takes email and password as arguments. The userCredential object contains the user property with user details.