feat: Add context to Cloud Code Triggers beforeLogin and afterLogin (#8724)

This commit is contained in:
Diamond Lewis
2023-09-20 03:47:35 -05:00
committed by GitHub
parent 05939858af
commit a9c34ef1e2
4 changed files with 38 additions and 4 deletions

View File

@@ -3327,7 +3327,7 @@ describe('beforeLogin hook', () => {
expect(req.headers).toBeDefined();
expect(req.ip).toBeDefined();
expect(req.installationId).toBeDefined();
expect(req.context).toBeUndefined();
expect(req.context).toBeDefined();
});
await Parse.User.signUp('tupac', 'shakur');
@@ -3444,7 +3444,7 @@ describe('afterLogin hook', () => {
expect(req.headers).toBeDefined();
expect(req.ip).toBeDefined();
expect(req.installationId).toBeDefined();
expect(req.context).toBeUndefined();
expect(req.context).toBeDefined();
});
await Parse.User.signUp('testuser', 'p@ssword');

View File

@@ -107,6 +107,36 @@ describe('Parse.User testing', () => {
}
});
it('user login with context', async () => {
let hit = 0;
const context = { foo: 'bar' };
Parse.Cloud.beforeLogin(req => {
expect(req.context).toEqual(context);
hit++;
});
Parse.Cloud.afterLogin(req => {
expect(req.context).toEqual(context);
hit++;
});
await Parse.User.signUp('asdf', 'zxcv');
await request({
method: 'POST',
url: 'http://localhost:8378/1/login',
headers: {
'X-Parse-Application-Id': Parse.applicationId,
'X-Parse-REST-API-Key': 'rest',
'X-Parse-Cloud-Context': JSON.stringify(context),
'Content-Type': 'application/json',
},
body: {
_method: 'GET',
username: 'asdf',
password: 'zxcv',
},
});
expect(hit).toBe(2);
});
it('user login with non-string username with REST API', async done => {
await Parse.User.signUp('asdf', 'zxcv');
request({