android - 在 Kotlin 的 Firebase Auth 中获取当前登录用户的 ID
问题描述
如何使用 Firebase Auth 在 Kotlin 中获取当前登录的用户 ID?我想用 ID 检索所述用户的完整信息以显示在 Activity 中。
解决方案
从获取当前登录用户的 Firebase 文档中:
val user = FirebaseAuth.getInstance().currentUser if (user != null) { // User is signed in } else { // No user is signed in }
然后,您可以从有关获取用户配置文件的文档中获取他用户的 UID,user.uid
如本示例所示:
val user = FirebaseAuth.getInstance().currentUser user?.let { // Name, email address, and profile photo Url val name = user.displayName val email = user.email val photoUrl = user.photoUrl // Check if user's email is verified val emailVerified = user.isEmailVerified // The user's ID, unique to the Firebase project. Do NOT use this value to // authenticate with your backend server, if you have one. Use // FirebaseUser.getToken() instead. val uid = user.uid }
推荐阅读
- compiler-errors - 用于在 Verilog 中打包和解包 3-D 数组的宏
- node.js - Mongoose:有没有办法通过使用单个 mongoose 更新操作来实现这个功能?
- visual-studio - 如何在没有 Visual Studio 的情况下使用 PVS-Studio 运行 .NET Core 项目?
- python - 决策树分类器如何处理全局约束?
- ios - 在 Swift 4 中使用 NSSetUncaughtExceptionHandler
- laravel - 查询生成器中的未定义变量
- spring-boot - Spring boot - Apache 反向代理背后的 Spring 安全性
- javascript - 为什么在 asp.net core 中实现 pjax 时 Request.Headers["X-PJAX"] 总是空的?
- node.js - 无法读取未定义的属性 \'findAll\'
- css - SCSS - 在元素后添加过渡