Reputation: 15903
FindOrCreate is suppose to either find
or create
based on the arguments you give it.
So I'm wondering why it's falling back to the catch
promise when data (a user)
is found, when it should just return the data
that was found to the .spread
function instead of trying to insert
the data that already exists?!.
As you can see below if there is a user found or created it's going to run the same function regardless. All that function is doing is creating an auth token
for the particular user. But for some reason it's going straight into the catch
promise!?
User.findOrCreate({
where: {
userId: details.userId,
},
defaults: {
name: details.name,
email: details.email,
},
attributes: ['userId', 'name', 'email', 'profilePic'],
}).spread(function (new_user, created) {
console.log("\n\nNew user was created T or F: ", created);
// Create the token and then pass it back to our callback along with the user details
user.createTokenForUser(new_user.userId, function(token) {
cb(token, new_user);
});
}).catch(function (err) {
// For some reason I'm running...?!??!?!?!?!
console.log("\n\n", err);
});
Upvotes: 1
Views: 636
Reputation: 1291
Did you try removing the trailing comma in the where statement? Its just hitting an error and that looks like a culprit :)
where: {
userId: details.userId,
}
to
where: {
userId: details.userId
}
Upvotes: 1