Skip to content

Commit b11e228

Browse files
committed
fix
1 parent 5018858 commit b11e228

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

src/Auth.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const Parse = require('parse/node');
2+
import { isDeepStrictEqual } from 'util';
23
import { getRequestObject, resolveError } from './triggers';
34
import { logger } from './logger';
45
import { LRUCache as LRU } from 'lru-cache';
@@ -468,16 +469,21 @@ const hasMutatedAuthData = (authData, userAuthData) => {
468469
return;
469470
}
470471

471-
// If provider exists, check if the id has changed
472-
// Only consider it mutated if the id is different
473-
// This prevents re-validation when auth adapters strip fields via afterFind
474-
if (providerData?.id !== userProviderAuthData?.id) {
472+
// Check if incoming data represents actual changes vs just echoing back
473+
// what afterFind returned. If incoming data is a subset of stored data
474+
// (all incoming fields match stored values), it's not mutated.
475+
// If incoming data has different values or fields not in stored data, it's mutated.
476+
// This handles the case where afterFind strips sensitive fields like 'code':
477+
// - Incoming: { id: 'x' }, Stored: { id: 'x', code: 'secret' } -> NOT mutated (subset)
478+
// - Incoming: { id: 'x', token: 'new' }, Stored: { id: 'x', token: 'old' } -> MUTATED
479+
const incomingKeys = Object.keys(providerData || {});
480+
const hasChanges = incomingKeys.some(key => {
481+
return !isDeepStrictEqual(providerData[key], userProviderAuthData[key]);
482+
});
483+
484+
if (hasChanges) {
475485
mutatedAuthData[provider] = providerData;
476-
return;
477486
}
478-
479-
// If id is the same, don't treat as mutation even if other fields differ
480-
// This handles the case where afterFind strips sensitive fields like 'code'
481487
});
482488
const hasMutatedAuthData = Object.keys(mutatedAuthData).length !== 0;
483489
return { hasMutatedAuthData, mutatedAuthData };

0 commit comments

Comments
 (0)