[英]How to authenticate a tablet user using firebase phone authentication?
[英]How to set diplayName of a firebase User while using Phone Authentication
我正在創建一個 android 按摩應用程序,我在其中實施 Firebase 電話身份驗證。 當我創建 PhoneAuthOptions 時,我沒有看到任何設置用戶 displayName 的方法,並且在驗證完成后,我需要用戶名將其與電話號碼一起保存到數據庫中。 在設置用戶的電話號碼時,我可以設置用戶的顯示名稱嗎?
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 活動代碼,當我獲取當前用戶的電話號碼時,我還想獲取用戶的 displayName。 我想將 displayName 存儲在 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()
}
}
}
用戶登錄后,您可以通過在其User
對象上調用updateProfile
來設置其顯示名稱,如有關更新用戶配置文件的文檔中所示。 從那里:
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.")
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.