Skip to content

Commit

Permalink
fix(directAccess/cloud-code): Pass installationId with LogIn (#6903)
Browse files Browse the repository at this point in the history
InstallationId didn't get passed correctly. Resulting in _Session without installationId

https://github.com/parse-community/parse-server/blob/master/src/Routers/UsersRouter.js#L263

* Fixed error with POST /login and req.query is undefined
  • Loading branch information
dplewis authored Sep 17, 2020
1 parent 90f396b commit 1246c90
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
31 changes: 31 additions & 0 deletions spec/ParseServerRESTController.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -662,4 +662,35 @@ describe('ParseServerRESTController', () => {
}
);
});

it('ensures logIn is saved with installationId', async () => {
const installationId = 'installation123';
const user = await RESTController.request(
'POST',
'/classes/_User',
{ username: 'hello', password: 'world' },
{ installationId }
);
expect(user.sessionToken).not.toBeUndefined();
const query = new Parse.Query('_Session');
let sessions = await query.find({ useMasterKey: true });

expect(sessions.length).toBe(1);
expect(sessions[0].get('installationId')).toBe(installationId);
expect(sessions[0].get('sessionToken')).toBe(user.sessionToken);

const loggedUser = await RESTController.request(
'POST',
'/login',
{ username: 'hello', password: 'world' },
{ installationId }
);
expect(loggedUser.sessionToken).not.toBeUndefined();
sessions = await query.find({ useMasterKey: true });

// Should clean up old sessions with this installationId
expect(sessions.length).toBe(1);
expect(sessions[0].get('installationId')).toBe(installationId);
expect(sessions[0].get('sessionToken')).toBe(loggedUser.sessionToken);
});
});
1 change: 1 addition & 0 deletions src/ParseServerRESTController.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ function ParseServerRESTController(applicationId, router) {
info: {
applicationId: applicationId,
sessionToken: options.sessionToken,
installationId: options.installationId,
context: options.context || {}, // Add context
},
query,
Expand Down
4 changes: 2 additions & 2 deletions src/Routers/UsersRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ export class UsersRouter extends ClassesRouter {
// Use query parameters instead if provided in url
let payload = req.body;
if (
(!payload.username && req.query.username) ||
(!payload.email && req.query.email)
(!payload.username && req.query && req.query.username) ||
(!payload.email && req.query && req.query.email)
) {
payload = req.query;
}
Expand Down

0 comments on commit 1246c90

Please sign in to comment.