You're viewing the legacy docs. They are deprecated as of May 18, 2016.
These docs are for version 2.4.2 and below of the Javascript SDK. Go to our current docs, or see our Web migration guide.

Version 2.4.2Changelog


Attaches a callback which listens for changes in authenticate state for a Firebase client. Your callback will be triggered for the initial authenticate state and again whenever the state changes. Use offAuth() to stop receiving updates, or getAuth() to access this data synchronously.

If a context is specified, the callback and context pair will be used to determine which callback to detach when calling offAuth().

If the client is unauthenticated, this method's callback will be passed null. Otherwise, the callback will be passed an object containing at least the following fields, and possibly more depending upon the provider used to authenticate:

authData object
Field Description Type
uid The user's unique ID across all providers. String
provider Unique string identifying the authentication provider, e.g. google. String
token The Firebase authentication token used to authenticate the client. String
expires The session expiration time in seconds since the Unix epoch. Number
auth The contents of the authentication token, available as the auth variable in your Security and Firebase Rules. Object
var ref = new Firebase("https://<YOUR-FIREBASE-APP>");
ref.onAuth(function(authData) {
  if (authData) {
    console.log("Authenticated with uid:", authData.uid);
  } else {
    console.log("Client unauthenticated.")