Complete the code to start observing authentication state changes.
firebase.auth().onAuthStateChanged([1]);The onAuthStateChanged method takes a callback function that runs when the auth state changes. Here, user => console.log(user) is a valid callback.
Complete the code to check if a user is signed in inside the observer.
firebase.auth().onAuthStateChanged(user => {
if ([1]) {
console.log('User signed in');
} else {
console.log('No user signed in');
}
});user.isSignedIn which does not exist.user === null to check signed in (this checks opposite).The user object is null if no user is signed in. Checking if (user) means the user is signed in.
Fix the error in the observer callback to correctly access the user's email.
firebase.auth().onAuthStateChanged(user => {
if (user) {
console.log('Email:', user[1]);
}
});user.email() which causes an error.getEmail() which does not exist.The user's email is accessed as a property user.email, not as a method.
Fill both blanks to unsubscribe the auth state observer correctly.
const unsubscribe = firebase.auth().onAuthStateChanged([1]); // Later when no longer needed [2]();
unsubscribe() immediately instead of storing it.firebase.auth().signOut which signs out user, not unsubscribes.The onAuthStateChanged returns an unsubscribe function. Store it in a variable and call it later with parentheses to unsubscribe.
Fill all three blanks to log a message only when a user signs out.
firebase.auth().onAuthStateChanged(user => {
if (user [1] null) {
console.log('User signed in');
} else if (user [2] null) {
console.log([3]);
}
});!= instead of !== which is less strict.Use !== null to check user signed in, === null to check signed out, and log the message string.