首页 > 解决方案 > 当用户在 C# 中使用电子邮件登录时如何获取用户 UID

问题描述

我想在用户在 C# 中成功登录后获取用户的 UID。

我正在尝试使用命令登录

auth.SignInWithEmailAndPasswordAsync()

它运行良好。但我想获取用户的 UID。请帮我。

标签: c#firebasefirebase-authentication

解决方案


您可以执行以下操作来获取 uid:

auth.SignInWithEmailAndPasswordAsync(email, password).ContinueWith(task => {
  if (task.IsCanceled) {
    Debug.LogError("SignInWithEmailAndPasswordAsync was canceled.");
    return;
  }
  if (task.IsFaulted) {
    Debug.LogError("SignInWithEmailAndPasswordAsync encountered an error: " + task.Exception);
    return;
  }

  Firebase.Auth.FirebaseUser newUser = task.Result;
  Debug.LogFormat("User signed in successfully: {0} ({1})",
      newUser.DisplayName, newUser.UserId);
});

检查文档:

https://firebase.google.com/docs/auth/unity/password-auth


推荐阅读