Skip to content

Commit ce34747

Browse files
authored
fix: Parameters missing in afterFind trigger of authentication adapters (#8458)
1 parent d05cfcd commit ce34747

File tree

4 files changed

+27
-4
lines changed

4 files changed

+27
-4
lines changed

spec/AuthenticationAdaptersV2.spec.js

+13
Original file line numberDiff line numberDiff line change
@@ -347,12 +347,25 @@ describe('Auth Adapter features', () => {
347347

348348
it('should strip out authData if required', async () => {
349349
const spy = spyOn(modernAdapter3, 'validateOptions').and.callThrough();
350+
const afterSpy = spyOn(modernAdapter3, 'afterFind').and.callThrough();
350351
await reconfigureServer({ auth: { modernAdapter3 }, silent: false });
351352
const user = new Parse.User();
352353
await user.save({ authData: { modernAdapter3: { id: 'modernAdapter3Data' } } });
353354
await user.fetch({ sessionToken: user.getSessionToken() });
354355
const authData = user.get('authData').modernAdapter3;
355356
expect(authData).toEqual({ foo: 'bar' });
357+
for (const call of afterSpy.calls.all()) {
358+
const args = call.args[0];
359+
if (args.user) {
360+
user._objCount = args.user._objCount;
361+
break;
362+
}
363+
}
364+
expect(afterSpy).toHaveBeenCalledWith(
365+
{ ip: '127.0.0.1', user, master: false },
366+
{ id: 'modernAdapter3Data' },
367+
undefined
368+
);
356369
expect(spy).toHaveBeenCalled();
357370
});
358371

src/Adapters/Auth/index.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ module.exports = function (authOptions = {}, enableAnonymousUsers = true) {
214214
return { validator: authDataValidator(provider, adapter, appIds, providerOptions), adapter };
215215
};
216216

217-
const runAfterFind = async authData => {
217+
const runAfterFind = async (req, authData) => {
218218
if (!authData) {
219219
return;
220220
}
@@ -230,7 +230,12 @@ module.exports = function (authOptions = {}, enableAnonymousUsers = true) {
230230
providerOptions,
231231
} = authAdapter;
232232
if (afterFind && typeof afterFind === 'function') {
233-
const result = afterFind(authData[provider], providerOptions);
233+
const requestObject = {
234+
ip: req.config.ip,
235+
user: req.auth.user,
236+
master: req.auth.isMaster,
237+
};
238+
const result = afterFind(requestObject, authData[provider], providerOptions);
234239
if (result) {
235240
authData[provider] = result;
236241
}

src/RestQuery.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -850,7 +850,12 @@ RestQuery.prototype.handleAuthAdapters = async function () {
850850
return;
851851
}
852852
await Promise.all(
853-
this.response.results.map(result => this.config.authDataManager.runAfterFind(result.authData))
853+
this.response.results.map(result =>
854+
this.config.authDataManager.runAfterFind(
855+
{ config: this.config, auth: this.auth },
856+
result.authData
857+
)
858+
)
854859
);
855860
};
856861

src/Routers/UsersRouter.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ export class UsersRouter extends ClassesRouter {
292292
if (authDataResponse) {
293293
user.authDataResponse = authDataResponse;
294294
}
295-
await req.config.authDataManager.runAfterFind(user.authData);
295+
await req.config.authDataManager.runAfterFind(req, user.authData);
296296

297297
return { response: user };
298298
}

0 commit comments

Comments
 (0)