Skip to main content
function onAuthStateChange(callback: OnAuthStateChangeFn): void;
Sets a callback function to be called when the authentication state changes, i.e. when a user signs in or out.

Parameters

ParameterTypeDescription
callbackOnAuthStateChangeFnThe callback function to be called when the authentication state changes.

Returns

void

Example

onAuthStateChange(async (user) => {
  if (user) {
    console.log("User signed in:", user.userId);
  } else {
    console.log("User signed out");
  }
});