Skip to content
This repository was archived by the owner on Mar 17, 2025. It is now read-only.

Commit 6adf9cf

Browse files
abeisgoatJacob Wenger
authored andcommitted
Improved error message for $firebaseAuth initialization and updated migration guide (#750)
1 parent 6ac5a0f commit 6adf9cf

File tree

3 files changed

+33
-4
lines changed

3 files changed

+33
-4
lines changed

docs/migration/1XX-to-2XX.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,36 @@ for details on how to upgrade to the Firebase `3.x.x` SDK.
2424

2525
## `$firebaseAuth` Method Renames / Signature Changes
2626

27+
The `$firebaseAuth` service now accepts an optional Firebase `auth` instance instead of a Firebase
28+
Database reference.
29+
30+
```js
31+
// Old
32+
$firebaseAuth(ref);
33+
34+
// New
35+
$firebaseAuth();
36+
// Or if you need to explicitly provide an auth instance
37+
$firebaseAuth(firebase.auth());
38+
```
39+
2740
Several authentication methods have been renamed and / or have different method signatures:
2841

2942
| Old Method | New Method | Notes |
3043
|------------|------------|------------------|
3144
| `$authAnonymously(options)` | `$signInAnonymously()` | No longer takes any arguments |
45+
| `$authWithPassword(credentials)` | `$signInWithEmailAndPassword(email, password)` | |
3246
| `$authWithCustomToken(token)` | `$signInWithCustomToken(token)` | |
3347
| `$authWithOAuthPopup(provider[, options])` | `$signInWithPopup(provider)` | `options` can be provided by passing a configured `firebase.database.AuthProvider` instead of a `provider` string |
3448
| `$authWithOAuthRedirect(provider[, options])` | `$signInWithRedirect(provider)` | `options` can be provided by passing a configured `firebase.database.AuthProvider` instead of a `provider` string |
49+
| `$authWithOAuthToken(provider, token)` | `$signInWithCredential(credential)` | Tokens must now be transformed into provider specific credentials. This is discussed more in the [Firebase Authentication guide](https://firebase.google.com/docs/auth/#key_functions). |
3550
| `$createUser(credentials)` | `$createUserWithEmailAndPassword(email, password)` | |
3651
| `$removeUser(credentials)` | `$deleteUser()` | Deletes the currently signed in user |
3752
| `$changeEmail(credentials)` | `$updateEmail(newEmail)` | Changes the email of the currently signed in user |
3853
| `$changePassword(credentials)` | `$updatePassword(newPassword)` | Changes the password of the currently signed in user |
3954
| `$resetPassword(credentials)` | `$sendPasswordResetEmail(email)` | |
4055
| `$unauth()` | `$signOut()` | |
41-
| `$onAuth(callback)` | `$onAuthStateChanged(callback)` |   |
56+
| `$onAuth(callback)` | `$onAuthStateChanged(callback)` | |
4257

4358

4459
## Auth Payload Format Changes

src/FirebaseAuth.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
/**
99
* This factory returns an object allowing you to manage the client's authentication state.
1010
*
11-
* @param {Firebase} ref A Firebase reference to authenticate.
11+
* @param {Firebase.auth.Auth} auth A Firebase auth instance to authenticate.
1212
* @return {object} An object containing methods for authenticating clients, retrieving
1313
* authentication state, and managing users.
1414
*/
@@ -24,9 +24,13 @@
2424
FirebaseAuth = function($q, $firebaseUtils, auth) {
2525
this._q = $q;
2626
this._utils = $firebaseUtils;
27-
if (typeof ref === 'string') {
28-
throw new Error('Please provide a Firebase reference instead of a URL when creating a `$firebaseAuth` object.');
27+
28+
if (typeof auth === 'string') {
29+
throw new Error('The $firebaseAuth service accepts a Firebase auth instance (or nothing) instead of a URL.');
30+
} else if (typeof auth.ref !== 'undefined') {
31+
throw new Error('The $firebaseAuth service accepts a Firebase auth instance (or nothing) instead of a Database reference.');
2932
}
33+
3034
this._auth = auth;
3135
this._initialAuthResolver = this._initAuthResolver();
3236
};

tests/unit/FirebaseAuth.spec.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,16 @@ describe('FirebaseAuth',function(){
9898
});
9999
});
100100

101+
it('will throw an error if a database reference is used in place of a Firebase auth instance',function(){
102+
expect(function(){
103+
$firebaseAuth(firebase.database().ref());
104+
}).toThrow();
105+
});
106+
107+
it('will not throw an error if an auth instance is provided',function(){
108+
$firebaseAuth(firebase.auth());
109+
});
110+
101111
describe('$signInWithCustomToken',function(){
102112
it('should return a promise', function() {
103113
expect(authService.$signInWithCustomToken('myToken')).toBeAPromise();

0 commit comments

Comments
 (0)