0

我想創建一個顯示用戶名和圖片的個人資料頁面。 但現在我一直在用用戶名掙扎。AngularJS - 使用Firebase和GoogleAuth顯示用戶名和圖片

配置文件頁面顯示用戶名和圖像,但現在用戶名與googAuth。

有沒有人知道如何做到這一點?

$scope.login = function() 
{ 
var ref = new   Firebase("https://fire.firebaseio.com"); 
     var authData = ref.getAuth(); 

     var userId = authData.uid; 
     var name = authData[authData.provider].displayName; 

    ref.authWithOAuthPopup("google", function(error, authData) 
    { 
     $timeout(function() { 

     $scope.username = name; 
     $scope.userid = userId; 
      console.log($scope.username); 
      console.log($scope.userid); 

     }); 



    if (error) 
     { 
      console.log("Login Failed!", error); 
     } 
    else 
    { 

     $state.go('tabsController.pendingTasks'); 
     ref.child("users").child(authData.uid).once("value",function(snapshot) 
     { 
     var ifExists = snapshot.exists(); 

      if(ifExists) 
      { 
       console.log("user already exists"); 
      } 
      else 
      { 
       ref.child("users").child(authData.uid).push({id:userId,name:name 
      } 

      ); 
      } 
     }); 

     } 
    }, 
    {remember: "sessionOnly", 
     scope: "email"}); 
} 

}) 

這似乎不起作用,因爲用戶名不顯示在我的離子視圖。 HTML部分如下。

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js</script> 
<ion-view title="Reminders" id="page7"> 
<ion-content padding="true" ng-controller="loginCtrl" class="hasheader"> 
    <div class="list card"> 
    <div class="item item-divider">{{username}}</span></div> 
     <div class="item item-body"> 
      <form class="list"> 
       <ion-checkbox>{{username}}</ion-checkbox> 
      </form> 
      </div> 
      </div> 

     </ion-content> 
    </ion-view> 

謝謝!

+0

如果我得到這個正確的,你想創建一個用戶配置文件,只要他們創建一個帳戶? –

+0

firebase安全性和規則可以阻止我在我的應用配置文件中公開這些信息嗎? –

回答

0

當用戶名不可用時,您正在查找用戶名。這將更好地工作:

var userId; 
var name; 

ref.authWithOAuthPopup("google", function(error, authData) 
{ 
    userId = authData.uid; 
    name = authData[authData.provider].displayName; 
    $timeout(function() { 
     $scope.username = name; 
     $scope.userid = userId; 
     console.log($scope.username); 
     console.log($scope.userid); 
    }); 
} 
+0

這個ddnt的工作我不知道如果有什麼錯誤即時通訊做或有權限即時通訊不包括,因爲這還沒有綁定仍然 –

+0

這修復了您的原代碼中的錯誤。如果這還不夠,可以考慮設置一個最小化的jsfiddle/jsbin來重現你的問題。堆棧溢出是幫助您調試非平凡代碼的糟糕工具。 –

相關問題