Passport.js : UID 是否唯一?

Passport.js : Are UID unique?

我有一个 Nodejs 应用程序,我使用 Passeport 让我的用户通过 Facebook 或 Google 通过 Oauth 进行连接。我在连接后存储基本数据,例如:uid、名字等。

如何确保我收到的 uid 对于给定用户始终是唯一的?我的意思是,数据要么来自 Facebook,要么来自 Google,那么为什么有一天我不能面对不同用户的令人讨厌的重复 uid 呢?

UID 仅在该单个提供商的用户列表范围内是唯一的。

This article 建议您将提供者的名称与 UID 组合起来以获得唯一值。

Combination of provider’s name and uID will uniquely identify user inside our app.

我会使用提供商的域名,例如“google.com”或“com.google”。

当您使用 Facebook 或 Google 时,您通过 OAuth 获得的 ID 是唯一的。但是,如果您想同时使用两者,那么我建议您像这样制作 dbSchema(如果您使用的是猫鼬)-

var userSchema = new mongoose.Schema({
  local: {
    username: String,
    password: String
  },
  facebook: {
    id: String,
    token: String,
    email: String,
    name: String
  },
  google: {
    id: String,
    token: String,
    email: String,
    name: String
  }
});