Skip to content

Commit

Permalink
Minor cleanup to $firebaseAuth code and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
jwngr committed Jun 2, 2016
1 parent a088284 commit ae4ef49
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
13 changes: 7 additions & 6 deletions docs/migration/1XX-to-2XX.md
Expand Up @@ -24,24 +24,25 @@ for details on how to upgrade to the Firebase `3.x.x` SDK.

## `$firebaseAuth` Method Renames / Signature Changes

Initializing `$firebaseAuth` has changed to accept an optional Firebase `auth` instance.
The `$firebaseAuth` service now accepts an optional Firebase `auth` instance instead of a Firebase
Database reference.

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

// New
$firebaseAuth()
$firebaseAuth();
// Or if you need to explicitly provide an auth instance
$firebaseAuth(firebase.auth())
$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)` |   |
| `$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 |
Expand All @@ -52,7 +53,7 @@ Several authentication methods have been renamed and / or have different method
| `$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
7 changes: 5 additions & 2 deletions src/FirebaseAuth.js
Expand Up @@ -24,9 +24,12 @@
FirebaseAuth = function($firebaseUtils, auth) {
this._utils = $firebaseUtils;

if (typeof auth === 'string' || auth.ref) {
throw new Error('Please provide a Firebase auth instance (or nothing) instead of a URL or Database reference 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
8 changes: 7 additions & 1 deletion tests/unit/FirebaseAuth.spec.js
Expand Up @@ -110,12 +110,18 @@ describe('FirebaseAuth',function(){
});

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

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();
});

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

Expand Down

0 comments on commit ae4ef49

Please sign in to comment.