Shane Shane - 1 year ago 79
Android Question

Properly log out a user from android app

I'm developing a small android app, and basically so far it just has login and logout functionality. I'm using Firebase to store user data and also for authentication.

So I have login working and it authenticates users as it should and I have logging out working in the sense that it

users. But is there anything I have to do from within the app to kill the session?

if (id == {
ref.unauth(); //End user session
startActivity(new Intent(MainActivity.this, LoginActivity.class)); //Go back to home page

Will this work as I think it should? Obviously if someone logs out they shouldn't be able to hit th back button and magically go back to the last page without re-logging in.

Answer Source

When Firebase authenticates the user (or you authenticate the user with Firebase), it stores the token for that user in local storage on your device. This happens when you call one of the authWith... methods (of course only if it successfully authenticates the user).

Calling ref.unauth(); immediately deletes that token from local storage.

A properly implemented flow would not automatically re-authenticate them when the user presses the back button, but that depends on the flow you implement (which is missing from your question and would likely be too much code anyway).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download