tUrG0n
tUrG0n

Reputation: 4448

Database Scheme for unified profiles fetched from multiple Social Networks (Facebook and Linkedin...)

The application I'm building allows users to login using both their Facebook and Linkedin Accounts in order to fetch their friend from these networks. Each of their friend can be a user of the application.

I have a couple of problems to solve:

  1. How should I structure my Database Schema?
  2. How do I unify profiles?

Potential Solutions

Regarding the structure:

I'm using mongo (But am open to suggestions). So I though that i'd create a collection of Users where each user document looks like this:

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

So, each user has:

  1. A unique app generated id (could be the doc's id for simplicity).
  2. An array of user's IDs. The IDs of their Friend's profiles created in my app.

Regarding Unifying profiles:

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

Misc

I though that I could use LoginRadius but i was using singly just for that, and then they suddenly decided to kill the service. In other words, I don't want to depend on a third party tool because this is a core feature.

Upvotes: 4

Views: 381

Answers (1)

Donald Derek
Donald Derek

Reputation: 2597

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'm using the Schema mentioned above for my users collection.

and when a new user wants to Sign up, using either the local strategy or social strategies

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

create an entry.

Upvotes: 1

Related Questions