Ember Firebase身份验证会话似乎没有注入

时间:2017-02-07 22:53:15

标签: ember.js

在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);
      },
    });

在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);

我使用firebase auth,它工作正常。但是,当我尝试在服务中创建的会话中注入当前用户时,sessionUsercurrentUser都会收到未定义的错误消息。我确实已经正确识别user1.email,因为这是如何定义用户模型的。有什么输入吗?

2 个答案:

答案 0 :(得分:1)

也许从更新开始:

console.log("currentUser in service session js"+currentUser);

console.log(`currentUser in service session js ${user}`);

答案 1 :(得分:1)

您可能还想尝试首次登录,并且只有在设置了currentUser:

之后
const sessionUser=this.get("session").login(user1);

类似于:

this.get("session").login(user1);
const.sessionUser = this.get("sessions.currentUser");