Skip to content

Commit

Permalink
Add a torii adapter for firebase
Browse files Browse the repository at this point in the history
Why:

* It would be great to use firebase authentication more easily.

This Commit:

* Merges the [torii-fire] addon into emberfire
* This adds a torii adapter for firebase

[torii-fire]: https://github.com/MattMSumner/torii-fire
  • Loading branch information
MattMSumner committed Jun 28, 2015
1 parent 1d3bd7b commit 3bfaa5b
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
20 changes: 20 additions & 0 deletions addon/torii-providers/firebase.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import Ember from "ember";

export default Ember.Object.extend({
firebased: Ember.inject.service(),
firebase: Ember.computed.alias('firebased.firebase'),

open: function(options) {
var self = this;

return new Ember.RSVP.Promise(function(resolve, reject) {
self.get("firebase").authWithOAuthPopup(options.authWith, function(error, authData) {
if (error) {
reject(error);
} else {
resolve(authData);
}
});
});
}
});
3 changes: 3 additions & 0 deletions app/torii-providers/firebase.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import FirebaseProvider from 'emberfire/torii-providers/firebase';

export default FirebaseProvider;
44 changes: 44 additions & 0 deletions tests/unit/torii-providers/firebase-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import Ember from 'ember';
import { describeModule, it } from 'ember-mocha';
import sinon from 'sinon';

describeModule('torii-provider:firebase', 'FirebaseProvider', {
needs: ['service:firebased'],
}, function() {

describe('#open', function() {
it('errors when firebase.authWithOAuthPopup errors', function() {
let provider = this.subject();
let errorMock = sinon.spy();
const firebaseMock = {
authWithOAuthPopup: sinon.stub().yields(errorMock)
};
provider.set('firebase', firebaseMock);

Ember.run(function() {
provider.open({authWith: 'errorProvider'}).catch(function(error) {
assert.ok(firebaseMock.authWithOAuthPopup.calledWith('errorProvider'));

assert.equal(error, errorMock);
});
});
});

it('returns authData when firebase.authWithOAuthPopup returns authData', function() {
let provider = this.subject();
let authDataMock = sinon.spy();
const firebaseMock = {
authWithOAuthPopup: sinon.stub().yields(null, authDataMock)
};
provider.set('firebase', firebaseMock);

Ember.run(function() {
provider.open({authWith: 'successProvider'}).then(function(authData) {
assert.ok(firebaseMock.authWithOAuthPopup.calledWith('successProvider'));

assert.equal(authData, authDataMock);
});
});
});
});
});

0 comments on commit 3bfaa5b

Please sign in to comment.