Emberfire session not recognising any functions this.get(...).fetch is not a function TypeError: this.get(...).fetch is not a function
I'm using emberfire to authenticate to a firebase database following the ember tutorial exactly with the following config:
//pods/application/route.js
beforeModel: function() {
return this.get("session").fetch().catch(function() {});
},
actions: {
signIn: function(provider) {
this.get('session').open('firebase', {
provider: 'password',
email: '[email protected]',
password: 'password1234'
});
},
signOut: function() {
this.get("session").close();
}
}
//app/torii-adapters/application.js
import ToriiFirebaseAdapter from 'emberfire/torii-adapters/firebase';
export default ToriiFirebaseAdapter.extend({
firebase: Ember.inject.service()
});
"emberfire": "^2.0.8",
"torii": "^0.9.6"
//config/environment
firebase: 'https://FIREBASE_DATABASE_NAME.firebaseio.com',
torii: {
sessionServiceName: 'session'
},
I get the following error:
router.js:936 Error while processing route: index this.get(...).fetch is not a function TypeError: this.get(...).fetch is not a function
Does anybody have any idea what's going on? I'm copying the tutorial to the letter.
+1
+1
I know this is super old, but you need to inject the service into the routes/controllers that need it. Also it looks like you are referencing your app/router.js file, when you should be doing this in either a controller (app/controller/controllerFile.js) or a route (app/routes/routeFile.js). Here's the docs on this.
// ⛔️ pods/application/route.js
// ✅ app/routes/route.js
import { inject as service } from '@ember/service';
export default Route.extend({
session: service(),
beforeModel: function() {
return this.get("session").fetch().catch(function() {});
},
actions: {
signIn: function(provider) {
this.get('session').open('firebase', {
provider: 'password',
email: '[email protected]',
password: 'password1234'
});
},
signOut: function() {
this.get("session").close();
}
}
})