Compare commits

...

3 Commits

Author SHA1 Message Date
Ruben Talstra
faf349e0db fix: Cosmos DB: E11000 duplicate key error
I’ve updated this PR to remove unique: true and sparse: true from the optional social login fields (googleId, facebookId, etc.) and switch them to simple indexes (index: true). This resolves the Cosmos DB “duplicate key” errors caused by multiple null values and ensures compatibility with both Cosmos DB and MongoDB. The email field remains required and unique, preserving overall identity uniqueness.
2025-02-12 19:22:37 +01:00
Ruben Talstra
915022bc08 Merge branch 'main' into partial-filter-index 2025-02-12 19:05:32 +01:00
Danny Avila
a1c7110a94 refactor(userSchema): unique index definitions using partialFilterExpression instead of sparse 2024-03-07 11:06:14 -05:00
2 changed files with 14 additions and 14 deletions

View File

@@ -84,38 +84,31 @@ const userSchema = mongoose.Schema(
},
googleId: {
type: String,
unique: true,
sparse: true,
index: true,
},
facebookId: {
type: String,
unique: true,
sparse: true,
index: true,
},
openidId: {
type: String,
unique: true,
sparse: true,
index: true,
},
ldapId: {
type: String,
unique: true,
sparse: true,
index: true,
},
githubId: {
type: String,
unique: true,
sparse: true,
index: true,
},
discordId: {
type: String,
unique: true,
sparse: true,
index: true,
},
appleId: {
type: String,
unique: true,
sparse: true,
index: true,
},
plugins: {
type: Array,

View File

@@ -3,6 +3,11 @@ const { isEnabled } = require('~/server/utils');
const { findUser } = require('~/models');
const { logger } = require('~/config');
/**
* Returns a function that handles the social login flow for a given provider.
* @param {string} provider - The provider name (e.g. 'google', 'facebook').
* @param {Function} getProfileDetails - A function to extract user details from the provider profile.
*/
const socialLogin =
(provider, getProfileDetails) => async (accessToken, refreshToken, idToken, profile, cb) => {
try {
@@ -31,6 +36,8 @@ const socialLogin =
});
return cb(null, newUser);
}
return cb(null, null);
} catch (err) {
logger.error(`[${provider}Login]`, err);
return cb(err);