T
T
Tolych2016-04-12 13:26:48
Node.js
Tolych, 2016-04-12 13:26:48

What is the best way to organize user models in sequelize?

Good afternoon!
If you are not logged in toaster.ru, you have the opportunity to register, log in with your username and password, or log in through social networks.
It became interesting how user records are created in this case and how to create them correctly.
For example, I register on the site through mail and password. In this case, the user is created through the User model.
And if we log in through social networks, how to create a user, because not all social networks provide email and password, then what should be in this case? Is it necessary to create your own model for each type of authorization, for facebook it will be facebook, with its own set of fields, for twitter its own model?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin Kitmanov, 2016-04-12
@k12th

It makes no sense to multiply models by the number of OAuth providers. Usually, as I understand it, SSO is implemented by searching the table for a user with such an email. Thus, the user can log in and register through anything, if the same address is specified. Enough field for email and password. You can optionally add fields like facebookId, twitterId, etc., and some other optional info that you can pull out. I did this and it works. If you have Postgre, then unstructured / optional information can be put in a JSON type cell.
With those providers that do not give mail, it is more difficult. From the UI point of view, it works like this: in your personal account there is a button like “link a Steam account”, by clicking it, the user is redirected to the Steam authorization. Now our task is to connect our user, with a well-known email, with such and such an ID given by Steam - sessions will help us.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question