我正嘗試使用Facebook登錄Ember應用程序。登錄操作正在工作,但我無法找到如何檢查用戶是否已在應用程序初始化時登錄。Emberjs:檢查用戶是否在初始化時使用Facebook登錄
我打電話給auth.authResponseChange
事件,但它阻止了應用程序,它永遠不會啓動。
App.ApplicationController = Ember.Controller.extend({
fbUser: false,
init: function() {
this.checkFBUser()
},
checkFBUser: function() {
FB.Event.subscribe('auth.authResponseChange', function(response) {
// this is never triggered and the app does not init
console.log(response)
if (response.status === 'connected') {
console.log('Logged in')
}
else {
FB.login()
}
})
},
// this works
actions: {
loginFacebook: function() {
var self = this
FB.login(function(response) {
if (response.authResponse) {
FB.api('/me', function(response) {
self.set('fbUser', response)
})
}
})
}
}
})
我該怎麼做?
但如果我把這個路線將只檢查了一定的網址嗎?登錄狀態必須在任何地方進行檢查。 (我是一個愚蠢的noob順便說一句,所以我不知道我在做什麼) – romainberger
您可以通過使用send方法發送信號,但應用程序控制器是一個有效的選項,並且可能比爲你的目的路線。我會更新答案。 –
我試過'getLoginStatus'但問題是一樣的,回調沒有被調用,應用程序沒有初始化 – romainberger