Database schema for unified profiles obtained from several social networks (Facebook and Linkedin ...)

The application that I create allows users to log in using both their Facebook and Linkedin accounts to get their friend from these networks. Each of their friends can be an application user.

I have several problems to solve:

  • How do I structure my database schema?
  • How to combine profiles?

Potential solutions

Regarding the structure:

I use mongo (but I'm open to suggestions). Therefore, however, I create collection Users , where each user document looks like this:

User = { appId: <id>, connections: [userId] }

So, each user has:

  • Unique identifier created by the application (may be a doc identifier for simplicity).
  • An array of user identifiers. The identifiers of their friends profiles created in my application.

Regarding the merging of profiles:

Should I group users based on their email or name? or both?

miscellanea

Although I could use LoginRadius , but I used singly just for this, and then they suddenly decided to kill the service. In other words, I do not want to depend on a third-party tool, because this is the main function.

+4
source share
1 answer
 var UserSchema = new Schema({ name: { type: String, default: '' }, email: { type: String, default: '' }, provider: { type: String, default: '' }, hashed_password: { type: String, default: '' }, salt: { type: String, default: '' }, authToken: { type: String, default: '' }, facebook: {}, linkedin: {} }) 

I use the scheme mentioned above for my user collection.

and when a new user wants to register using either a local strategy or social strategies

I just use the mongoose update function with the "upsert: true" option to either update or

create a record.

+1
source

Source: https://habr.com/ru/post/1495711/


All Articles