External User Fix (#2220)

* fix: fixed bug with user upserting

* chore: version bump
This commit is contained in:
Wyatt Johnson
2019-03-11 19:35:22 +00:00
committed by GitHub
parent 049357a09c
commit 32962aa1e8
2 changed files with 9 additions and 2 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "talk",
"version": "4.8.1",
"version": "4.8.2",
"description": "A better commenting experience from Mozilla, The New York Times, and the Washington Post. https://coralproject.net",
"main": "app.js",
"private": true,
+8 -1
View File
@@ -60,6 +60,7 @@ async function upsertUser(
shouldSetDisplayName = false
) {
let user = await User.findOne({
id,
profiles: {
$elemMatch: {
id,
@@ -80,6 +81,7 @@ async function upsertUser(
// The user was not found, lets create them!
user = new User({
id,
username,
lowercaseUsername: username.toLowerCase(),
profiles: [{ id, provider }],
@@ -798,8 +800,13 @@ class Users {
* @param {Object} token a jwt token used to sign in the user
*/
static async findOrCreateByIDToken(id, token) {
// FIXME: (wyattjoh) adding the `{ 'profiles.id': id }` search condition is
// a workaround for the `upsertExternalUser` bug where the ID being set was
// incorrect. Patch the user creation functions to adapt to the correct
// behavior. Thankfully, this is currently still covered by an index.
// Try to get the user.
let user = await User.findOne({ id });
let user = await User.findOne({ $or: [{ id }, { 'profiles.id': id }] });
// If the user was not found, try to look it up.
if (user === null) {