fix: Parse.Query.select('authData') for _User class doesn't return auth data (#10055)

This commit is contained in:
Manuel
2026-02-12 20:45:41 +00:00
committed by GitHub
parent 1af6c0dc1f
commit 44a5bb105e
3 changed files with 50 additions and 0 deletions
+13
View File
@@ -1395,6 +1395,19 @@ describe('Parse.User testing', () => {
});
});
it('should return authData when select authData with masterKey', async () => {
const provider = getMockFacebookProvider();
Parse.User._registerAuthenticationProvider(provider);
const user = await Parse.User._logInWith('facebook');
const query = new Parse.Query(Parse.User);
query.select('authData');
const result = await query.get(user.id, { useMasterKey: true });
expect(result.get('authData')).toBeDefined();
expect(result.get('authData').facebook).toBeDefined();
expect(result.get('authData').facebook.id).toBe('8675309');
expect(result.get('authData').facebook.access_token).toBe('jenny');
});
it('only creates a single session for an installation / user pair (#2885)', async done => {
Parse.Object.disableSingleInstance();
const provider = getMockFacebookProvider();
+17
View File
@@ -254,8 +254,25 @@ module.exports = function (authOptions = {}, enableAnonymousUsers = true) {
);
};
// Returns the list of auth provider names that have a valid adapter configured.
// This includes both built-in providers and custom providers from authOptions.
const getProviders = function () {
const allProviders = new Set([...Object.keys(providers), ...Object.keys(authOptions)]);
if (!_enableAnonymousUsers) {
allProviders.delete('anonymous');
}
return [...allProviders].filter(provider => {
try {
return !!loadAuthAdapter(provider, authOptions);
} catch {
return false;
}
});
};
return Object.freeze({
getValidatorForProvider,
getProviders,
setEnableAnonymousUsers,
runAfterFind,
});
+20
View File
@@ -751,6 +751,26 @@ _UnsafeRestQuery.prototype.runFind = async function (options = {}) {
findOptions.keys = this.keys.map(key => {
return key.split('.')[0];
});
// When selecting `authData` on `_User`, also add the internal auth data fields
// (e.g. `_auth_data_facebook`) for each configured auth provider. In MongoDB,
// `authData` is stored as individual `_auth_data_<provider>` fields, so the
// projection for `authData` alone won't match them. Adding both ensures it
// works across all database adapters: Mongo uses `_auth_data_*` fields,
// Postgres uses the `authData` column directly.
//
// Note: When selecting `authData`, only auth data of currently configured
// providers is returned. Auth data entries of providers that are no longer
// configured won't be included. To return all auth data regardless of the
// provider configuration, do not use `authData` as a selected key.
if (this.className === '_User' && findOptions.keys.includes('authData')) {
const providers = this.config.authDataManager.getProviders();
for (const provider of providers) {
const key = `_auth_data_${provider}`;
if (!findOptions.keys.includes(key)) {
findOptions.keys.push(key);
}
}
}
}
if (options.op) {
findOptions.op = options.op;