Closed mohitsud closed 4 years ago
I basically took code from 2.0.10 and added it to torii-adapters/firebase.js to get it to work on 3.0.0-rc6
import ToriiFirebaseAdapter from 'emberfire/torii-adapters/firebase';
import Ember from 'ember';
export default ToriiFirebaseAdapter.extend({
/**
* Restore existing authenticated session
*
* @return {Promise}
*/
fetch() {
return this.fetchAuthState_()
.then((user) => {
if (!user) {
return this.fetchRedirectState_();
}
return user;
})
.then((user) => {
if (!user) {
return Ember.RSVP.reject(new Error('No session available'));
}
return this.open(user);
})
.catch((err) => Ember.RSVP.reject(err));
},
/**
* Fetches the redirect user, if any.
*
* @return {!Promise<?firebase.User>}
* @private
*/
async fetchRedirectState_() {
let auth = await this.get('firebaseApp').auth();
return auth.getRedirectResult()
.then(result => result.user);
},
/**
* Promisifies the first value of onAuthStateChanged
*
* @return {!Promise<?firebase.User>}
* @private
*/
async fetchAuthState_() {
return new Ember.RSVP.Promise(async (resolve, reject) => {
let auth = await this.get('firebaseApp').auth();
const unsub = auth.onAuthStateChanged((user) => {
unsub();
resolve(user);
},
(err) => {
unsub();
reject(err);
});
});
},
});
Steps to reproduce
this.get('session').fetch