在使用电话身份验证时,如何设置firebase用户的外交名称

发布于 2025-02-13 21:31:37 字数 1513 浏览 0 评论 0 原文

我正在创建一个正在实施Firebase电话身份验证的Android按摩应用程序。当我创建PhoneAuthOptions时,我没有看到任何设置用户显示名称的方法,在验证完成后,我需要用户名称将其保存在数据库中。在设置用户的语音数时,我可以设置用户的显示名称吗?

     val options=PhoneAuthOptions.newBuilder(mAuth)
         .setPhoneNumber(number)
         .setTimeout(60L,TimeUnit.SECONDS)
         .setActivity(this)
         .setCallbacks(callbacks)
         .build()
     PhoneAuthProvider.verifyPhoneNumber(options)
     Log.d("MSG","Auth started")
  }

这是OTP活动代码,当我获得CurrentUser的PhoneNumber时,我也想获取用户的DisplayName。我想在UID代替商店displayName。

        mAuth.signInWithCredential(credential)
            .addOnCompleteListener(this){ task->
                if(task.isSuccessful){
                    val pref : SharedPreferences = getSharedPreferences("login", MODE_PRIVATE)
                    val editor : SharedPreferences.Editor = pref.edit()
                    editor.putBoolean("LogedIn", true).apply()
                    mDB = FirebaseDatabase.getInstance()
                    mDBRef = mDB.getReference()

                    val phoneNumber = mAuth.currentUser?.phoneNumber!!
                    val uid = mAuth.currentUser?.uid!!
                    mDBRef.child("Users").child(phoneNumber).setValue(uid)

                    startActivity(Intent(this, MainActivity::class.java))
                    finish()
                }
                else {
                    Toast.makeText(this, "Invalid OTP", Toast.LENGTH_SHORT).show()
                }
            }
    }

I am creating an android massaging app where I am implementing Firebase Phone Authentication. When I am creating PhoneAuthOptions, I am not seeing any method to set User's displayName, and after the verification completion I need User's name to save it with phone number into Database. While setting up phoneNumber of the User, is there any I can set displayName of the User?

     val options=PhoneAuthOptions.newBuilder(mAuth)
         .setPhoneNumber(number)
         .setTimeout(60L,TimeUnit.SECONDS)
         .setActivity(this)
         .setCallbacks(callbacks)
         .build()
     PhoneAuthProvider.verifyPhoneNumber(options)
     Log.d("MSG","Auth started")
  }

Here is the OTP activity code, I want to get User's displayName also, when I am getting currentUser's phoneNumber. and I want store displayName in the place of uid.

        mAuth.signInWithCredential(credential)
            .addOnCompleteListener(this){ task->
                if(task.isSuccessful){
                    val pref : SharedPreferences = getSharedPreferences("login", MODE_PRIVATE)
                    val editor : SharedPreferences.Editor = pref.edit()
                    editor.putBoolean("LogedIn", true).apply()
                    mDB = FirebaseDatabase.getInstance()
                    mDBRef = mDB.getReference()

                    val phoneNumber = mAuth.currentUser?.phoneNumber!!
                    val uid = mAuth.currentUser?.uid!!
                    mDBRef.child("Users").child(phoneNumber).setValue(uid)

                    startActivity(Intent(this, MainActivity::class.java))
                    finish()
                }
                else {
                    Toast.makeText(this, "Invalid OTP", Toast.LENGTH_SHORT).show()
                }
            }
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

薯片软お妹 2025-02-20 21:31:38

登录用户后,您可以通过调用 Update Profile 在其用户对象上设置其显示名称,如。从那里:

val user = Firebase.auth.currentUser

val profileUpdates = userProfileChangeRequest {
    displayName = "Jane Q. User"
    photoUri = Uri.parse("https://example.com/jane-q-user/profile.jpg")
}

user!!.updateProfile(profileUpdates)
        .addOnCompleteListener { task ->
            if (task.isSuccessful) {
                Log.d(TAG, "User profile updated.")
            }
        }

Once the user is signed in, you can set their display name by calling updateProfile on their User object as shown in the documentation on updating the user's profile. From there:

val user = Firebase.auth.currentUser

val profileUpdates = userProfileChangeRequest {
    displayName = "Jane Q. User"
    photoUri = Uri.parse("https://example.com/jane-q-user/profile.jpg")
}

user!!.updateProfile(profileUpdates)
        .addOnCompleteListener { task ->
            if (task.isSuccessful) {
                Log.d(TAG, "User profile updated.")
            }
        }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文