Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm trying to store an authorized user id variable, which I can pass to controllers. I know there's an issue with how I'm trying to pass the data from inside the closure of my factory object, but I'm stuck on how to fix it.

Here is my factory:

myApp.factory('Authentication', function($firebase, 
  $firebaseAuth, FIREBASE_URL, $location) {

  var ref = new Firebase(FIREBASE_URL);
  var simpleLogin = $firebaseAuth(ref);

  var authorized;

  var myObject = {
    login : function() {
    return simpleLogin.$authAnonymously().then(function(authData) {
    authorized = authData.uid;
  console.log("Logged in as:", authData.uid);
}).catch(function(error) {
  console.error("Authentication failed:", error);
});
    },
    auth : authorized
  } //myObject

  return myObject;
});

Here is my controller:

myApp.controller('MeetingsController', 


function($scope, $firebase, Authentication) {

  var ref = new Firebase('http://i2b2icons.firebaseio.com/');
  var meetings = $firebase(ref);

  $scope.authid = Authentication.auth;

  $scope.meetings = meetings.$asObject();
//  $scope.id = = Authentication.login.id;  
  $scope.addMeeting=function() {
    meetings.$push({
      name: $scope.meetingname,
      date: Firebase.ServerValue.TIMESTAMP
    }).then(function() {
      $scope.meetingname = '';
    });
  } //addmeeting

  $scope.deleteMeeting=function(key) {
    meetings.$remove(key);
  } //deletemeeting

}); //MeetingsController

I'm really just trying to get the $scope.authid variable to pick up the value of auuthorized from the the login function of myObject.

The login method should have been called already by logging in via this controller:

myApp.controller('RegistrationController', 


function($scope, $firebaseAuth, $location, Authentication) {


  $scope.login = function() {
    Authentication.login();
  } //login


}); //RegistrationController
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
172 views
Welcome To Ask or Share your Answers For Others

1 Answer

Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...