英文:
Set persistence for user in firebase authentication (kotlin)
问题
Hi,我是新手学生,正在尝试使用Kotlin编程。我希望用户能在进入应用程序时自动登录,前提是我的用户共享偏好设置中的内容不为空(我在那里存储用户ID)。我不太理解Firebase身份验证令牌的整体工作方式,也不知道如何在用户第一次登录后为其设置持久性,或者Kotlin是否支持此功能,因为我知道Firebase管理员可以设置某种刷新令牌。所以我需要关于这方面的一些知识,也许还需要一些关于我尝试实现的目标是否可行的专家意见。提前感谢您的帮助。我尝试使用signInWithCustomToken(),但我不知道如何创建正确格式的自定义令牌。
英文:
Hi i am quite new to kotlin programming, still a student in degree and now im trying to create some sort of persistence where the user is able to auto log in when they enter the app with the condition that the content in my user shared preference is not empty(where i store my user ID)
I dont quite understand how firebase authentication token work as a whole and how to somehow set some sort of persistence for the user after they log in the first time or is it just not possible with kotlin because i am aware that firebase admin you are somehow able to set some sort of refresh tokens
so i am in need of some knowledge about this and maybe some expert opinion on what im trying to achieve is feasible or not. Thank you in advance
tried signInWithCustomToken() but i dont understand how to create a proper format of custom tokens
答案1
得分: 0
当您使用Firebase SDK登录时,它会自动将凭证持久化到设备的本地存储。当用户重新启动应用程序时,Firebase SDK会自动读取这些凭证,并尝试恢复用户的登录状态。
您可以监听该恢复过程和其他状态更改,如:在Android中监听身份验证状态。您不需要自定义令牌,因此我建议使用内置提供程序。
英文:
When you sign in with the Firebase SDK, it automatically persist the credentials to local storage on the device. When the user restarts the app, the Firebase SDK automatically reads those credentials and tries to restore the user's sign-in state.
You can listen to that restore process and other state changes as shown in: Listen for authentication state in Android. You don't need custom tokens for that, so I'd recommend using one of the built-in providers.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论