Firebase为同一用户生成两个不同的UID?

发布于 2025-02-09 12:28:50 字数 232 浏览 0 评论 0原文

目前正在研究一个利用Firebase存储用户的React项目。为了使用户使用CreateUserWitheMailandPassword()。当用户在firebase中创建用户时,它将用户存储在看起来像-n4xrz的ID下...

但是,当我打电话以获取用户的UID(通过usercredential.user.uid)时,它会返回更长的一个这看起来像是Firebase生成的典型UID,并且与用户的父ID并不相同。关于这可能是什么想法?

Currently working on a React project that utilizes Firebase to store users. To make the user, I use createUserWithEmailAndPassword(). When the user is created in Firebase, it stores the user under an id that looks like -N4xrZ...

However, when I make a call to get the user's UID (through userCredential.user.uid), it returns a much longer one that looks like a typical UID generated by Firebase and that isn't the same as the user's parent id. Any ideas as to what this may be?

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

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

发布评论

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

评论(1

短叹 2025-02-16 12:28:50

它将用户存储在看起来像-n4xrz ...

的ID下

这是您使用push()以来的预期行为。此函数每次都会生成唯一的ID。

当我打电话以获取用户的UID(通过usercredential.user.uid)时,它返回了一个更长的效果,看起来像是firebase生成的典型UID,并且与用户的父ID不同。

来自身份验证过程的UID与Push()生成的UID不同。实际上,每次启动应用程序时都一样。因此,当您将数据写入数据库时​​,请停止使用push()并使用UID:

firebase.database().ref('users/' + userCredential.user.uid).set({
    username: name,
    email: email,
    profile_picture : imageUrl
});

It stores the user under an id that looks like -N4xrZ...

That's the expected behavior since you're using push(). This function generates a unique ID each time is called.

When I make a call to get the user's UID (through userCredential.user.uid), it returns a much longer one that looks like a typical UID generated by Firebase and that isn't the same as the user's parent id.

The UID that comes from the authentication process, it's different than the one that is generated by push(). It's actually the same, each time you launch your app. So when you write data to the database, stop using push() and use the UID:

firebase.database().ref('users/' + userCredential.user.uid).set({
    username: name,
    email: email,
    profile_picture : imageUrl
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文