Firebase Sign Out Not Working in Swift

Firebase sign out not working in Swift


2020 ...

do { try Auth.auth().signOut() }
catch { print("already logged out") }

Typically, on your "base" screen, something like ...

func logoutUser() {
// call from any screen

do { try Auth.auth().signOut() }
catch { print("already logged out") }

navigationController?.popToRootViewController(animated: true)
}

Sign Out of Firebase in Swift 4

This always works for me:

do {
try Auth.auth().signOut()
} catch let error {
print("Error: ", error.localizedDescription)
}

If this isn't working for you, provide us with some more context. What do you mean by "it's not working"? If you use this code provided, it will tell what error you're encountering.

Firebase user can not be logged out - Swift

I had this exact same problem. Since this happens when you relaunch, try putting this code in your app.delegate.

FIRAuth.auth()?.addAuthStateDidChangeListener { auth, user in
if let user = user {
// User is signed in.
} else {
// No user is signed in.
}
}

Writing to Firestore after logging out the Firebase authenticated user


Is there a way to authenticate and start the Firestore write and logout the user in the meantime, not having to wait for the write to finish?*

Unforetunately no. Once you call the signOut() method, it invalidates your auth token. If the write operation reaches successfully before it can invalidate the token, then it may succeed. Otherwise it will fail.

Is there a way to somehow cache this Firestore write until the phone is online again, even if the app has been closed in between?*

Firestore supports offline persistence by default, meaning all writes you perform (except for Transactions) will be cached and will get executed once you are connected to the internet.

It is generally a better practice anyways to do the cleanup in the back-end since the Firebase admin SDK bypasses security rules, you will be able to cleanup data that are otherwise inaccessible to your mobile clients.



Related Topics



Leave a reply



Submit