从Android应用程序正确注销一个用户 [英] Properly log out a user from android app

查看:286
本文介绍了从Android应用程序正确注销一个用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个小型的android应用程序,到目前为止,它只是登录和注销功能。我正在使用Firebase存储用户数据并进行身份验证。所以我登录工作,它认证用户,因为它应该和我注销工作的意义上说,它 unauthenticates

  if(id == R.id.action_log_out){
ref.unauth(); //最终用户会话
startActivity(new Intent(MainActivity.this,LoginActivity.class)); //返回主页
finish();
}

按照我的想法,这会工作吗?很显然,如果有人注销,他们不应该能够击中后退按钮,神奇地返回到最后一页,而无需重新登录。

解决方案

当Firebase对用户进行身份验证(或者使用Firebase对用户进行身份验证)时,会将该用户的令牌存储在设备的本地存储中。当你调用其中一个 authWith ... 方法时(当然只有当它成功地认证用户时)才会发生这种情况。



调用 ref.unauth(); 立即从本地存储中删除该令牌。


$ b

当用户按下后退按钮时,将不会自动重新验证它们,但这取决于您实现的流程(从您的问题中缺少该流程,并且可能会有太多的代码)。


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 unauthenticates users. But is there anything I have to do from within the app to kill the session?

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

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.

解决方案

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).

这篇关于从Android应用程序正确注销一个用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆