Skip to content

Commit

Permalink
Merge e0db263 into 40bfbbc
Browse files Browse the repository at this point in the history
  • Loading branch information
abeisgoat committed Jun 2, 2016
2 parents 40bfbbc + e0db263 commit 1a4bd67
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
17 changes: 16 additions & 1 deletion docs/migration/1XX-to-2XX.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,36 @@ for details on how to upgrade to the Firebase `3.x.x` SDK.

## `$firebaseAuth` Method Renames / Signature Changes

The `$firebaseAuth` service now accepts an optional Firebase `auth` instance instead of a Firebase
Database reference.

```js
// Old
$firebaseAuth(ref);

// New
$firebaseAuth();
// Or if you need to explicitly provide an auth instance
$firebaseAuth(firebase.auth());
```

Several authentication methods have been renamed and / or have different method signatures:

| Old Method | New Method | Notes |
|------------|------------|------------------|
| `$authAnonymously(options)` | `$signInAnonymously()` | No longer takes any arguments |
| `$authWithPassword(credentials)` | `$signInWithEmailAndPassword(email, password)` | |
| `$authWithCustomToken(token)` | `$signInWithCustomToken(token)` | |
| `$authWithOAuthPopup(provider[, options])` | `$signInWithPopup(provider)` | `options` can be provided by passing a configured `firebase.database.AuthProvider` instead of a `provider` string |
| `$authWithOAuthRedirect(provider[, options])` | `$signInWithRedirect(provider)` | `options` can be provided by passing a configured `firebase.database.AuthProvider` instead of a `provider` string |
| `$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). |
| `$createUser(credentials)` | `$createUserWithEmailAndPassword(email, password)` | |
| `$removeUser(credentials)` | `$deleteUser()` | Deletes the currently signed in user |
| `$changeEmail(credentials)` | `$updateEmail(newEmail)` | Changes the email of the currently signed in user |
| `$changePassword(credentials)` | `$updatePassword(newPassword)` | Changes the password of the currently signed in user |
| `$resetPassword(credentials)` | `$sendPasswordResetEmail(email)` | |
| `$unauth()` | `$signOut()` | |
| `$onAuth(callback)` | `$onAuthStateChanged(callback)` |   |
| `$onAuth(callback)` | `$onAuthStateChanged(callback)` | |


## Auth Payload Format Changes
Expand Down
10 changes: 7 additions & 3 deletions src/FirebaseAuth.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/**
* This factory returns an object allowing you to manage the client's authentication state.
*
* @param {Firebase} ref A Firebase reference to authenticate.
* @param {Firebase.auth.Auth} auth A Firebase auth instance to authenticate.
* @return {object} An object containing methods for authenticating clients, retrieving
* authentication state, and managing users.
*/
Expand All @@ -23,9 +23,13 @@

FirebaseAuth = function($firebaseUtils, auth) {
this._utils = $firebaseUtils;
if (typeof ref === 'string') {
throw new Error('Please provide a Firebase reference instead of a URL when creating a `$firebaseAuth` object.');

if (typeof auth === 'string') {
throw new Error('The $firebaseAuth service accepts a Firebase auth instance (or nothing) instead of a URL.');
} else if (typeof auth.ref !== 'undefined') {
throw new Error('The $firebaseAuth service accepts a Firebase auth instance (or nothing) instead of a Database reference.');
}

this._auth = auth;
this._initialAuthResolver = this._initAuthResolver();
};
Expand Down
10 changes: 10 additions & 0 deletions tests/unit/FirebaseAuth.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,16 @@ describe('FirebaseAuth',function(){
});
});

it('will throw an error if a database reference is used in place of a Firebase auth instance',function(){
expect(function(){
$firebaseAuth(firebase.database().ref());
}).toThrow();
});

it('will not throw an error if an auth instance is provided',function(){
$firebaseAuth(firebase.auth());
});

describe('$signInWithCustomToken',function(){
it('should return a promise', function() {
expect(authService.$signInWithCustomToken('myToken')).toBeAPromise();
Expand Down

0 comments on commit 1a4bd67

Please sign in to comment.