Question

I have 2 ways for users to create an account on my website.

a. Normal Registration Form (email, password) b. Registration via Facebook Connect (fb_userid, email)

Which is the best practice to implement this using MySQL (InnoDB engine) ?

My approach:

[USER]
user_id
user_type (normal/facebook)

[USER_NORMAL]
user_normal_id
user_id
email
password

[USER_FACEBOOK]
user_facebook_id
user_id
email
fb_userid

What do you suggest?

Was it helpful?

Solution 4

If those are the only fields then it's probably easiest to put all the fields in one table and have NULLs as appropriate.

However, if you want a normalised design you would go for something like this:

[USER]
user_id (PK)
email
(Other fields common to both)

[USER_NORMAL]
user_id (PK, FK to USER.user_id)
password
(Other fields specific to 'normal')

[USER_FACEBOOK]
user_id (PK, FK to USER.user_id)
fb_userid
(Other fields specific to FB)

If 'password' is the only field specific to 'normal' users and there are many fields specific to FB users then a compromise might be to have two tables: USER (as above but containing 'password') and USER_FACEBOOK

OTHER TIPS

This single table would be more simple (in my opinion):

user (user_id, user_email, user_password, user_fbid)

You don't need a "type" because you can use a CASE to determine if user_fbid is NULL then it's a "normal" account, else if user_password is NULL then it's a Facebook account.

I would have two tables.

One table should contain basic user information:

user (user_id, user_email, user_password)

The other table should be generic and link 3rd party accounts to these users. Example:

user_ext (type, user_id, uid)

The type field should contain the type of service (in this case Facebook), and the unique identifier for the service (in this case the Facebook User ID). It should then link back to the user_id.

This strategy will then allow you to add additional services that users can authenticate against in the future.

I would keep everything on one table and differenciate them by if they have a Facebook Id or not.

I would probably prefer to keep all users in 1 table. You can have fields that are null if that user's type doesn't have that field. For example fb_userid can be null if the user is normal.

[USER]
user_id
user_type (normal/facebook)
email
password    
fb_userid (can be null: yess)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top