Created
July 12, 2016 23:59
-
-
Save steven-ferguson/8eddf63123fa74066e9d92f7e829d8e9 to your computer and use it in GitHub Desktop.
Emberfire + FirebaseUI Authentication
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* globals firebaseui */ | |
import Ember from 'ember'; | |
import firebase from 'firebase'; | |
const { computed, inject: { service } } = Ember; | |
export default Ember.Component.extend({ | |
firebaseApp: service(), | |
didInsertElement() { | |
this._super(...arguments); | |
this._initializeAuthUI(); | |
}, | |
signInSuccess() {}, | |
uiConfig: computed('signInSuccess', function () { | |
return { | |
signInOptions: [ | |
firebase.auth.EmailAuthProvider.PROVIDER_ID, | |
], | |
callbacks: { | |
signInSuccess: this.get('signInSuccess'), | |
}, | |
}; | |
}), | |
elementId: 'firebaseui-auth-container', | |
_initializeAuthUI() { | |
const auth = this.get('firebaseApp').auth(); | |
const ui = new firebaseui.auth.AuthUI(auth); | |
ui.start('#firebaseui-auth-container', this.get('uiConfig')); | |
this.set('ui', ui); | |
}, | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Add these to the bottom of your head tag --> | |
<script src="https://www.gstatic.com/firebasejs/ui/live/0.4/firebase-ui-auth.js"></script> | |
<link type="text/css" rel="stylesheet" href="https://www.gstatic.com/firebasejs/ui/live/0.4/firebase-ui-auth.css" /> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
const { inject: { service } } = Ember; | |
export default Ember.Controller.extend({ | |
session: service(), | |
actions: { | |
signInSuccess() { | |
this.get('session').fetch().then(() => this.replaceRoute('index')); | |
}, | |
} | |
}); |
This gist appears to be using older versions of the Ember API, and there have been some major changes in the intervening years in the API and the separation of concerns between the various parts. Any suggestions on how to use this with Ember 3.19? I've been toying around with it and will update if I reach a solution.
Unfortunately I have not used Ember in 3 years, so I am not familiar with any api changes that have occurred since then.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Really helpful Steve. I´m a newbe using your auth code but the line 6 session: service(), in login.js controller gets me Attempting to inject an unknown injection: 'service:session' Error. when comment this line the auth Works fine cause can see my firebase data so I´m authenticated the problem is cannot fetch the session cause result undefined on line 10. Any help will be appreciated.