(protected) new FirebaseInstance(name, adminToken)
Creates a new reference to a Firebase instance.
NOTE: don't use the constructor yourself, use a FirebaseAccount
instance instead.
Parameters:
Name | Type | Description |
---|---|---|
name |
String | The name of the Firebase. |
adminToken |
String | The administrative token to use |
- Source:
- See:
Methods
-
addAuthToken() → {external:Promise}
-
Promises to create and return a new auth token.
- Source:
Returns:
A promise that resolves with a new auth token (String) that is guaranteed to be valid and rejects with an Error if there's an error.- Type
- external:Promise
Example
instance.addAuthToken().then(function(token) { fb.auth(token, function(err) { // err should be null }); });
-
getAuthTokens() → {Promise}
-
Promises to get all the auth tokens associated with the instance.
- Source:
Returns:
A promise that resolves with an Array of the instance's currently-valid auth tokens and rejects with an Error if there's an error.- Type
- Promise
Example
instance.getAuthTokens().then(function(tokens) { fb.auth(tokens[0], function(err) { // err should be null }); });
-
getRules() → {external:Promise}
-
Promises to get a Javascript object containing the current security rules. NOTE: the top-level "rules" part of the JSON will be stripped.
- Source:
Returns:
A promise that resolves with an Object containing the rules if they're retrieved successfully and rejects with an Error if there's an error.- Type
- external:Promise
Example
instance.getRules().then(function(rules) { if (rules['.read'] === 'true' && rules['.write'] === 'true') { console.log('WARNING: this Firebase has default global rules!'); } });
-
removeAuthToken(token) → {external:Promise}
-
Promises to remove an existing auth token.
Parameters:
Name Type Description token
String The token to be removed. - Source:
Returns:
A promise that resolves if token has been removed successfully and rejects with an Error if token isn't valid or if there's an error.- Type
- external:Promise
Example
instance.removeAuthToken(token).then(function() { fb.auth(token, function(err) { // should get an error indicating invalid credentials here }); });
-
setRules(newRules) → {external:Promise}
-
Promises to change current security rules.
Parameters:
Name Type Description newRules
Object The new security rules as a Javascript object. This object need not have a top-level "rules" key, although it will be handled gracefully if it does. - Source:
Returns:
A promise that resolves if the rules are changed successfully and rejects with an Error if there's an error.- Type
- external:Promise
Example
instance.setRules({ '.read': 'true', '.write': 'false' }).then(function() { console.log('Disabled write access to this Firebase.'); }).catch(function() { console.log('Oops, something went wrong!'); });
-
toString() → {String}
-
Gets the URL to the instance, for use with the Firebase API.
- Source:
Returns:
The full URL to the instance.- Type
- String
Example
var fb = new Firebase(instance.toString());