Skip to content

Commit 5018858

Browse files
Copilotmtrezza
andcommitted
Fix hasMutatedAuthData to only validate when provider id changes
Co-authored-by: mtrezza <[email protected]>
1 parent 629b2da commit 5018858

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

spec/AuthenticationAdaptersV2.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1362,7 +1362,7 @@ describe('Auth Adapter features', () => {
13621362
simpleAdapter: { id: 'simple1' },
13631363
// codeBasedAdapter is NOT modified (no new code provided)
13641364
});
1365-
1365+
13661366
// This should succeed without requiring 'code' for codeBasedAdapter
13671367
await user.save(null, { sessionToken });
13681368

src/Auth.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
const Parse = require('parse/node');
2-
import { isDeepStrictEqual } from 'util';
32
import { getRequestObject, resolveError } from './triggers';
43
import { logger } from './logger';
54
import { LRUCache as LRU } from 'lru-cache';
@@ -456,9 +455,29 @@ const hasMutatedAuthData = (authData, userAuthData) => {
456455
if (provider === 'anonymous') { return; }
457456
const providerData = authData[provider];
458457
const userProviderAuthData = userAuthData[provider];
459-
if (!isDeepStrictEqual(providerData, userProviderAuthData)) {
458+
459+
// If unlinking (setting to null), consider it mutated
460+
if (providerData === null) {
461+
mutatedAuthData[provider] = providerData;
462+
return;
463+
}
464+
465+
// If provider doesn't exist in stored data, it's new
466+
if (!userProviderAuthData) {
460467
mutatedAuthData[provider] = providerData;
468+
return;
461469
}
470+
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) {
475+
mutatedAuthData[provider] = providerData;
476+
return;
477+
}
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'
462481
});
463482
const hasMutatedAuthData = Object.keys(mutatedAuthData).length !== 0;
464483
return { hasMutatedAuthData, mutatedAuthData };

0 commit comments

Comments
 (0)