emberfire icon indicating copy to clipboard operation
emberfire copied to clipboard

Emberfire session not recognising any functions this.get(...).fetch is not a function TypeError: this.get(...).fetch is not a function

Open rij12 opened this issue 8 years ago • 3 comments

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.

rij12 avatar Dec 17 '17 02:12 rij12

+1

k-dauda avatar Feb 04 '18 21:02 k-dauda

+1

lookininward avatar Nov 14 '18 20:11 lookininward

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

fentech avatar Mar 13 '19 16:03 fentech