I am a Sequelize beginner. I'd like to oAuth authenticate with Twitter or Facebook and want to save user information in the database.
But if OAuth authentication is done on multiple sites, there is a problem that information such as userid
registered in the database will collide with the other sites.
In order to avoid this, I would like to do a process to update the database only when the specified userid
does not already exist in the database.
I knew that we could use Sequelize's findOrCreate
to do it, but I do not know how to use findOrCreate
.
I know how to use upsert and I'd like to use findOrCreate
like the description of upsert below. However, we want to perform conditional branching like this:
if (userid! = "○○○" && username! = "○○○")
.
User.upsert({
userid: profile.id,
username: profile.username,
accountid: c + 1,
}).then(() => {
done(null, profile);
});
What should I do?