0

ユーザー名と画像を表示するプロファイルページを作成したいとします。 しかし、今のところ私はUsernameに苦労しています。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を設定することを検討してください。 Stack Overflowは、自明ではないコードをデバッグするのに役立つ厄介なツールです。 –

関連する問題