2015-11-08 16 views
1

我有成功的重定向身份驗證到/從GitHub後獲取AngularFire的$ onAuth()觸發問題。如果我使用auth.$authWithOAuthRedirect('github'),它將重定向到GitHub,並在成功驗證後再返回,但當它返回到我的Angular應用程序時,auth.$onAuth()回調不會被調用。如果我然後刷新頁面,它會使用預期的authinfo進行調用。如果我退出($unauth())並重新登錄,則在刷新頁面之前,不會再調用$onAuth()回調。

起初,我想這是我做錯了,但我發現,如果我更改代碼使用$authWithOAuthPopup()相反,應用程序按預期工作:在$onAuth()回調儘快稱爲彈出關閉,傳遞的authData。

注意確定這是否是AngularFire中的一個錯誤,如果我誤解了如何使用它。我搜索了一些例子,我想我正確地使用它,但如果問題出在我的代碼中,請告訴我應該如何做。

我已經把一個最小的回購案例放入GitHub回購:https://github.com/drstearns/angularfire-oath-redir。代碼當前使用$authWithOAuthRedirect,並且您會注意到,當您首次驗證身份時從GitHub返回時,在您退出並重新登錄後也沒有任何內容記錄到控制檯。如果在登錄後刷新頁面,它將起作用精細。如果你改變它使用$authWithOAuthPopup(),它也可以正常工作。

下面是相關的代碼片段:

angular.module('ChatApp', ['firebase']) 
    .constant('firebaseUrl', 'https://info343chat.firebaseio.com') 
    .controller('ChatController', function($scope, $firebaseArray, $firebaseObject, $firebaseAuth, firebaseUrl) { 
     //create reference to the Firebase 
     var rootRef = new Firebase(firebaseUrl); 

     //create an authentication service for this firebase 
     var auth = $firebaseAuth(rootRef); 

     //when the user clicks the signin button... 
     $scope.signin = function() { 
      //authenticate with github using a popup window 
      //BUG? change this to $authWithOAuthPopup and 
      //it works correctly 
      auth.$authWithOAuthRedirect('github') 
       .catch(function(err) { 
        console.error(err); 
       }); 
     }; 

     //when the user clicks the signout button... 
     $scope.signout = function() { 
      //un-authenticate (sign out) 
      auth.$unauth(); 
     }; 

     //when the authentication state changes... 
     auth.$onAuth(function(authData) { 
      //for debugging 
      //not firing after initial redirect back from GitHub 
      console.log('$onAuth'); 
      console.log(authData); 

      //if we have authentication data 
      if (authData) { 
       //... 
      } 
      else { 
       //... 
      } 
     }); //$onAuth() 

     //...other controller code 
    }); //ChatController 

回答

1

謝謝你的報告!這確實是一個bug,雖然它實際上是在firebase.js本身。幸運的是,它最近修復了。如果您將您的firebase.js參考從2.2.4更新到2.3.1,則應解決問題。

相關問題