私はIonic Frameworkの下でアプリケーションを開発しており、Firebaseも使用しています。何があってもFirebaseでユーザをログインさせ続けるには?
ここで、数時間後やアプリのクラッシュやデバイスの再起動後に認証が失われることがあります。
何が起こっても、いつも自分のユーザーにログインさせることができますか? (例えばFacebookのような)ここ
がページlogin.htmlとから、私のログインコントローラです:
.controller('loginController',['$scope', '$firebaseArray', 'CONFIG', '$document', '$state', function($scope, $firebaseArray, CONFIG, $document, $state) {
// Perform the login action when the user submits the login form
$scope.doLogin = function(userLogin) {
if($document[0].getElementById("user_name").value != "" && $document[0].getElementById("user_pass").value != ""){
firebase.auth().signInWithEmailAndPassword(userLogin.username, userLogin.password).then(function() {
var userId = firebase.auth().currentUser.uid;
firebase.database().ref('accounts/' + userId + '/currentBusiness/').update({
name: "No current business arround",
description: "Seems there's nothing arround...",
})
$state.go("tab.favorites");
}, function(error) {
// An error happened.
var errorCode = error.code;
var errorMessage = error.message;
if (errorCode === 'auth/invalid-email') {
alert('Enter a valid email.');
return false;
}else if (errorCode === 'auth/wrong-password') {
alert('Incorrect password.');
return false;
}else if (errorCode === 'auth/argument-error') {
alert('Password must be string.');
return false;
}else if (errorCode === 'auth/user-not-found') {
alert('No such user found.');
return false;
}else if (errorCode === 'auth/too-many-requests') {
alert('Too many failed login attempts, please try after sometime.');
return false;
}else if (errorCode === 'auth/network-request-failed') {
alert('Request timed out, please try again.');
return false;
}else {
alert(errorMessage);
return false;
}
});
}else{
alert('Please enter email and password');
return false;
}//end check client username password
};// end $scope.doLogin()
}])
私はこの質問に答える方法を理解していません。この質問に答えるには、elseブロックに何が入っているかを示す必要があります。その結果、ユーザーが再度サインインすることなくFirebaseがユーザーオブジェクトをリロードする方法を実際に確認することができます。 –