を私はその後、私は
logOutOutlet
とbookingsOutlet
が隠されている、ログアウトしてlogInOutlet
ボタンショーXcodeのシミュレータでアプリを実行して、ユーザーとパスワードでログインします。これまでのところ、期待通りに動作します。Firebaseユーザーがログアウトすることはできません - スウィフト
次に、Xcodeのからアプリを停止し、再度実行しますが、私はすでにログインしているかのように今では動作しますlogOutOutlet
を示し、bookingsOutletは、logInOutletを隠します。アプリが一時停止、終了、削除されたときも同じ動作をします。 次のViewControllerでアクティブなLogInセッションがあると仮定して、FireBaseリアルタイムデータベースからデータを取得しようとしますが、このエラーが発生します。 Error Domain=com.firebase Code=1 "Permission Denied" UserInfo={NSLocalizedDescription=Permission Denied}. Why can I not log out completely?
@IBAction func logOut(sender: AnyObject) {
// if the current user is logged in, try to log out and if logout is successful:
// hide: logOut button & bookings button
// show: logIn button
if FIRAuth.auth() != nil {
do {
try FIRAuth.auth()?.signOut()
print("the user is logged out")
} catch let error as NSError {
print(error.localizedDescription)
print("the current user id is \(FIRAuth.auth()?.currentUser?.uid)")
}
self.logInOutlet.hidden = false
self.logOutOutlet.hidden = true
self.bookingsOutlet.hidden = true
} // end of if.. FIRAuth.auth()
}
override func viewDidLoad() {
super.viewDidLoad()
// if the user is logged out
// hide: logOut button & bookings button
// show: logIn button
// if FIRAuth.auth()?.currentUser?.uid == nil {
if FIRAuth.auth() == nil {
self.logInOutlet.hidden = false
self.logOutOutlet.hidden = true
self.bookingsOutlet.hidden = true
// it still prints the user id, why?
if let userNOTLogged = FIRAuth.auth()?.currentUser?.uid {
print("User should NOT be logged \(userNOTLogged)")
}
// if the user is logged in
// hide: logIn Button
// show: logOut button & bookings button
} else if
FIRAuth.auth() != nil {
self.logInOutlet.hidden = true
self.logOutOutlet.hidden = false
self.bookingsOutlet.hidden = false
}
}
// Log in code
FIRAuth.auth()?.signInWithEmail(email.text!, password: password.text!, completion: { (authData, error) in
let customError = error?.localizedDescription
if error != nil {
print(customError)
// display an alert with the error
self.displayAlert()
} else {
print("The user has been logged in")
//if signIn was successful, instantiate the view controller with identifier SWrevelViewidentifier
let toMenuOptions = self.storyboard?.instantiateViewControllerWithIdentifier("SWrevelViewidentifier")
self.presentViewController(toMenuOptions!, animated: true, completion: nil)
}
})
}
サードパーティのログインを使用していますか?そうであれば、GIDSignIn.sharedInstance()のような対応するコマンドを使わなければならないかもしれません。signOut() – andrew
私のコードが機能しなかったのは、.auth()がFIRAuthによって返されたオブジェクトであり、ユーザー。 currentUserの値を取得するには、FIRAuth.auth()!. currentUserをチェックする必要があります。この場合、返される値はnilまたはログインしているユーザーになる可能性があります。あなたが 'addAuthStateDidChangeListener'も提案したように動作します。 – bibscy