kotlin 将个人资料图片添加到firebase,同时也向其他用户显示

vwkv1x7d  于 7个月前  发布在  Kotlin
关注(0)|答案(1)|浏览(79)

我有一个Kotlin应用程序,我想在我的个人资料页面上添加一个个人资料图片,但我也想为管理员帐户,他可以看到姓名/电子邮件和个人资料图片的列表。
我已经看到老问题,他们在哪里存储它firestore,而不是firebase-auth,这似乎效率低下,因为我正在为这两个调用。我应该存储所有用户数据在数据库中,或者有更好的方法来做到这一点,同时仍然能够有一个管理页面。
这里有一些相关的代码来显示我的项目的结构。我有其他的功能,但他们似乎无关紧要。

class AuthViewModel : ViewModel() {
    private val auth: FirebaseAuth = FirebaseAuth.getInstance()
    private val authEventsChannel = Channel<AuthEvent>()
    val authEvents = authEventsChannel.receiveAsFlow()
    private val db = Firebase.firestore

    val currentUser
        get() = auth.currentUser

    fun uploadProfileImage(it: Uri) {}

字符串
这里是前端

@Composable
fun ProfileScreen(navController: NavHostController) {
    val authViewModel: AuthViewModel = viewModel()
    val currentUser = authViewModel.currentUser
    var showImagePicker by remember { mutableStateOf(false) }
    val profileImageUri = remember { mutableStateOf<Uri?>(null) }

    val imagePickerLauncher = rememberLauncherForActivityResult(
        contract = ActivityResultContracts.GetContent()
    ) { uri: Uri? ->
        uri?.let {
            profileImageUri.value = it
            authViewModel.uploadProfileImage(it)
        }
    }

Button(onClick = {
            showImagePicker = true
        }) {
            Text("Change Profile Picture")
        }
        profileImageUri.value?.let { uri ->
            Image(
                painter = rememberAsyncImagePainter(uri),
                contentDescription = "Profile Picture",
                modifier = Modifier.size(100.dp)
            )
        }

8ulbf1ek

8ulbf1ek1#

没有“官方”的方式在你的应用程序中列出用户。
Firebase Admin SDK有一个API来列出所有用户,但这些API不能直接从客户端使用,并且不关注此类用例的性能。
实现此用例的常见方法是从Firebase Auth加载当前用户的配置文件,并从另一个数据源加载有关其他用户数据的信息。
另请参阅:

相关问题