Skip to content

Commit 7db1f8e

Browse files
committed
Revert "Optimize authData handling logic and integrate delta-based updates"
This reverts commit 7669bd9.
1 parent 7669bd9 commit 7db1f8e

File tree

4 files changed

+108
-528
lines changed

4 files changed

+108
-528
lines changed

spec/AuthenticationAdaptersV2.spec.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -829,7 +829,6 @@ describe('Auth Adapter features', () => {
829829
expect(firstCall[2].user.id).toEqual(user.id);
830830
expect(firstCall.length).toEqual(3);
831831

832-
payload.someData = false;
833832
await user.save({ authData: { baseAdapter2: payload } }, { useMasterKey: true });
834833

835834
const secondCall = baseAdapter2.validateAuthData.calls.argsFor(1);

spec/Users.authdata.spec.js

Lines changed: 0 additions & 260 deletions
This file was deleted.

src/Auth.js

Lines changed: 3 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -423,15 +423,10 @@ const findUsersWithAuthData = async (config, authData, beforeFind) => {
423423
const queries = await Promise.all(
424424
providers.map(async provider => {
425425
const providerAuthData = authData[provider];
426-
if (!providerAuthData) {
427-
return null;
428-
}
429426

430-
if (beforeFind) {
431-
const adapter = config.authDataManager.getValidatorForProvider(provider)?.adapter;
432-
if (typeof adapter?.beforeFind === 'function') {
433-
await adapter.beforeFind(providerAuthData);
434-
}
427+
const adapter = config.authDataManager.getValidatorForProvider(provider)?.adapter;
428+
if (beforeFind && typeof adapter?.beforeFind === 'function') {
429+
await adapter.beforeFind(providerAuthData);
435430
}
436431

437432
if (!providerAuthData?.id) {
@@ -606,70 +601,6 @@ const handleAuthDataValidation = async (authData, req, foundUser) => {
606601
return acc;
607602
};
608603

609-
const subsetEqual = (prev, next) => {
610-
if (prev === next) return true;
611-
if (prev == null || next == null) return false;
612-
613-
const tp = typeof prev;
614-
const tn = typeof next;
615-
if (tn !== 'object' || tp !== 'object') return prev === next;
616-
617-
// arrays: require element-wise equality for the provided portion
618-
if (Array.isArray(next)) {
619-
if (!Array.isArray(prev)) return false;
620-
if (next.length !== prev.length) return false;
621-
for (let i = 0; i < next.length; i++) {
622-
if (!subsetEqual(prev[i], next[i])) return false;
623-
}
624-
return true;
625-
}
626-
627-
// objects: every provided key in `next` must match `prev`
628-
for (const k of Object.keys(next)) {
629-
const nv = next[k];
630-
if (typeof nv === 'undefined') continue; // treat "not provided" as no-op
631-
const pv = prev[k];
632-
if (!subsetEqual(pv, nv)) return false;
633-
}
634-
return true;
635-
}
636-
637-
/**
638-
* Delta between current and incoming authData with partial update semantics:
639-
* - changed: providers truly changed (new or value differs on provided keys)
640-
* - unlink: providers explicitly set to null (remove without validation)
641-
* - unchanged: providers either absent in incoming or provided as matching subset
642-
*/
643-
const diffAuthData = (current = {}, incoming = {}) => {
644-
const changed = {};
645-
const unlink = {};
646-
const unchanged = {};
647-
648-
const providers = new Set([...Object.keys(current), ...Object.keys(incoming)]);
649-
for (const p of providers) {
650-
const prev = current[p];
651-
const next = incoming[p];
652-
653-
if (next === null) { unlink[p] = true; continue; }
654-
if (typeof next === 'undefined') { // provider untouched
655-
if (typeof prev !== 'undefined') unchanged[p] = prev;
656-
continue;
657-
}
658-
if (typeof prev === 'undefined') { // new provider
659-
changed[p] = next;
660-
continue;
661-
}
662-
663-
// key point: treat sanitized partial payload (subset) as unchanged
664-
if (subsetEqual(prev, next)) {
665-
unchanged[p] = prev;
666-
} else {
667-
changed[p] = next;
668-
}
669-
}
670-
return { changed, unlink, unchanged };
671-
};
672-
673604
module.exports = {
674605
Auth,
675606
master,
@@ -683,6 +614,4 @@ module.exports = {
683614
hasMutatedAuthData,
684615
checkIfUserHasProvidedConfiguredProvidersForLogin,
685616
handleAuthDataValidation,
686-
subsetEqual,
687-
diffAuthData
688617
};

0 commit comments

Comments
 (0)