mardi 7 février 2017

Ember session doesn't seem injected successfully

in services\session.js:

    import Ember from 'ember';

    export default Ember.Service.extend({
      currentUser: null,
      login(user){
        this.set('currentUser', user);
        console.log("currentUser in service session js"+currentUser);
      },
    });

in index.js:

export default Ember.Route.extend({
    firebaseApp: Ember.inject.service(),
    session: Ember.inject.service(),


        beforeModel() {
        const auth = this.get('firebaseApp').auth();
        const user1 = auth.currentUser;

        if ((user1 !== null)&&(user1 !== undefined)&&(user1 !== ""))
        {
            const em=user1.email;
            const sessionUser=this.get("session").login(user1);

            console.log("this is email in index route beforeModel "+em);
            console.log("this is sessionUser email in index route beforeModel "+sessionUser);

I use firebase auth, which works fine. However, when i try to inject currect user in session i created in service, neither "sessionUser" nor "currentUser" got undefined error message. I do have user1.email recognized correctly since that's how user model is defined. Any inputs?




Aucun commentaire:

Enregistrer un commentaire