2016-01-22 128 views
0
我無法重定向成功登錄後,用戶

後重定向,我讀過了火力地堡的文檔,並試圖幾件事情,但至今沒有運氣電子郵件認證

任何人都可以點我到正確的方向?

在此先感謝, 熱雷米。

這裏的controller.js

.controller('LoginCtrl', function($scope, $ionicPopup, $state, Auth) { 
$scope.data = {}; 

$scope.login = function() { 
     Auth.login($scope.data.email, $scope.data.password).then(function() { 
     $state.go("tab-discover"); 
       }) 

    .error(function() { 
     var alertPopup = $ionicPopup.show({ 
      title: 'Mauvais identifiants', 
      template: 'Veuillez recommencer' 
     }); 
    }); 
} 

$scope.signup = function() { 
     Auth.signup($scope.data.email, $scope.data.password) 
    .error(function() { 
     var alertPopup = $ionicPopup.show({ 
      title: 'Erreur', 
      template: 'Un probleme est survenu' 
     }); 
     }); 
    } 

    }) 

而且services.js

.factory("Auth", function(FURL, $firebaseAuth) { 


    var ref = new Firebase(FURL); 
    var auth = $firebaseAuth(ref); 
    var Auth = { 
    user: {}, 

login: function(email, password){ 
    console.log("loginService", email, password); 

    return ref.authWithPassword({ 
    "email": email, 
    "password": password 
    }, function(error, authData) { 


    if (error) { 
    console.log("La connexion a echoué!", error); 
    } else { 
    console.log("Authenticated successfully with payload:", authData); 
    } 
}) 
    }, 
    signup: function(email, password){ 
     console.log("signupService", email, password); 
     return ref.createUser({ 
     "email": email, 
     "password": password 
     }, function(error, userData) { 
    if (error) { 
    switch (error.code) { 
     case "EMAIL_TAKEN": 
     console.log("The new user account cannot be created because the email is already in use."); 
     break; 
     case "INVALID_EMAIL": 
     console.log("The specified email is not a valid email."); 
     break; 
     default: 
     console.log("Error creating user:", error); 
    } 
    } else { 
    console.log("Successfully created user account with uid:", userData.uid); 
    } 
}).then(function(){ 
     return Auth.login(email, password); 
    }) 
    } 
} 
return Auth; 
}) 
+0

重定向,比如'了window.location =「someotherlocation 「;'? – Filipe

+0

@Filipe OP是採用了棱角分明的路由重定向,在$ state.go(..)線 – aw04

回答

0

看起來火力使用,你試圖把它返回與then承諾回調。一個簡單的解決將是一個回調傳遞給您的登錄功能,並調用它的火力點回調中:

login: function(email, password, callback, onError){ 
    console.log("loginService", email, password); 

    ref.authWithPassword({ 
    "email": email, 
    "password": password 
    }, function(error, authData) { 

    if (error) { 
    onError(error); 
    } else { 
    callback(authData); 
    } 
}) 

然後調用它像這樣:

Auth.login($scope.data.email, $scope.data.password, function (data) { 
    console.log("Authenticated successfully with payload:", data); 
    $state.go("tab-discover"); 
}, function (error) { 
    console.log("La connexion a echoué!", error); 
}); 
+0

我得到750853錯誤類型錯誤:在範圍無法讀取屬性「然後」未定義 $ scope.login(HTTP://本地主機:8100/JS/controllers.js:7:62)和751852警告火力警告:異常是由用戶回調拋出。類型錯誤:回調不是一個函數 –

+0

我刪除了,然後從代碼,如果你得到的錯誤是不是我提供的 – aw04

+0

你說得對,我的壞 感謝現在的工作 –