在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,它工作正常。但是,当我尝试在服务中创建的会话中注入当前用户时,sessionUser
和currentUser
都会收到未定义的错误消息。我确实已经正确识别user1.email
,因为这是如何定义用户模型的。有什么输入吗?
答案 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");