From 3b7e2256fc1c61cce4cca2992f6f0e16a371b0fa Mon Sep 17 00:00:00 2001 From: "Gabriel Mowses (Mouse)" Date: Wed, 1 Apr 2026 21:06:12 -0300 Subject: [PATCH] fix: update processProfile for Wiki.js 3.0 schema (no providerId column) --- server/models/users.mjs | 54 +++++++---------------------------------- 1 file changed, 9 insertions(+), 45 deletions(-) diff --git a/server/models/users.mjs b/server/models/users.mjs index fed596e1..a1be43f0 100644 --- a/server/models/users.mjs +++ b/server/models/users.mjs @@ -127,13 +127,6 @@ export class User extends Model { static async processProfile({ profile, providerKey }) { const provider = get(WIKI.auth.strategies, providerKey, {}) - provider.info = find(WIKI.data.authentication, ['key', provider.stategyKey]) - - // Find existing user - let user = await WIKI.db.users.query().findOne({ - providerId: toString(profile.id), - providerKey - }) // Parse email let primaryEmail = '' @@ -153,19 +146,8 @@ export class User extends Model { } primaryEmail = primaryEmail.toLowerCase() - // Find pending social user - if (!user) { - user = await WIKI.db.users.query().findOne({ - email: primaryEmail, - providerId: null, - providerKey - }) - if (user) { - user = await user.$query().patchAndFetch({ - providerId: toString(profile.id) - }) - } - } + // Find existing user by email (Wiki.js 3.0 schema) + let user = await WIKI.db.users.query().findOne({ email: primaryEmail }) // Parse display name let displayName = '' @@ -191,45 +173,27 @@ export class User extends Model { // Update existing user if (user) { if (!user.isActive) { - throw new WIKI.Error.AuthAccountBanned() + throw new Error('ERR_ACCOUNT_BANNED') } if (user.isSystem) { throw new Error('This is a system reserved account and cannot be used.') } user = await user.$query().patchAndFetch({ - email: primaryEmail, - name: displayName, - pictureUrl: pictureUrl + name: displayName }) - if (pictureUrl === 'internal') { - await WIKI.db.users.updateUserAvatarData(user.id, profile.picture) - } - return user } - // Self-registration - if (provider.selfRegistration) { - // Check if email domain is whitelisted - if (get(provider, 'domainWhitelist', []).length > 0) { - const emailDomain = last(primaryEmail.split('@')) - if (!provider.domainWhitelist.includes(emailDomain)) { - throw new WIKI.Error.AuthRegistrationDomainUnauthorized() - } - } - - // Create account + // Create new user (auto-register from OAuth) + { user = await WIKI.db.users.query().insertAndFetch({ - providerKey: providerKey, - providerId: toString(profile.id), email: primaryEmail, name: displayName, - pictureUrl: pictureUrl, - locale: WIKI.config.lang.code, - defaultEditor: 'markdown', - tfaIsActive: false, + auth: JSON.stringify({ [providerKey]: { provider: true } }), + prefs: JSON.stringify({}), + meta: JSON.stringify({}), isSystem: false, isActive: true, isVerified: true