feat: Add context to Cloud Code Triggers beforeLogin and afterLogin (#8724)
This commit is contained in:
@@ -3327,7 +3327,7 @@ describe('beforeLogin hook', () => {
|
|||||||
expect(req.headers).toBeDefined();
|
expect(req.headers).toBeDefined();
|
||||||
expect(req.ip).toBeDefined();
|
expect(req.ip).toBeDefined();
|
||||||
expect(req.installationId).toBeDefined();
|
expect(req.installationId).toBeDefined();
|
||||||
expect(req.context).toBeUndefined();
|
expect(req.context).toBeDefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
await Parse.User.signUp('tupac', 'shakur');
|
await Parse.User.signUp('tupac', 'shakur');
|
||||||
@@ -3444,7 +3444,7 @@ describe('afterLogin hook', () => {
|
|||||||
expect(req.headers).toBeDefined();
|
expect(req.headers).toBeDefined();
|
||||||
expect(req.ip).toBeDefined();
|
expect(req.ip).toBeDefined();
|
||||||
expect(req.installationId).toBeDefined();
|
expect(req.installationId).toBeDefined();
|
||||||
expect(req.context).toBeUndefined();
|
expect(req.context).toBeDefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
await Parse.User.signUp('testuser', 'p@ssword');
|
await Parse.User.signUp('testuser', 'p@ssword');
|
||||||
|
|||||||
@@ -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 => {
|
it('user login with non-string username with REST API', async done => {
|
||||||
await Parse.User.signUp('asdf', 'zxcv');
|
await Parse.User.signUp('asdf', 'zxcv');
|
||||||
request({
|
request({
|
||||||
|
|||||||
@@ -259,7 +259,8 @@ export class UsersRouter extends ClassesRouter {
|
|||||||
req.auth,
|
req.auth,
|
||||||
Parse.User.fromJSON(Object.assign({ className: '_User' }, user)),
|
Parse.User.fromJSON(Object.assign({ className: '_User' }, user)),
|
||||||
null,
|
null,
|
||||||
req.config
|
req.config,
|
||||||
|
req.info.context
|
||||||
);
|
);
|
||||||
|
|
||||||
// If we have some new validated authData update directly
|
// If we have some new validated authData update directly
|
||||||
@@ -291,7 +292,8 @@ export class UsersRouter extends ClassesRouter {
|
|||||||
{ ...req.auth, user: afterLoginUser },
|
{ ...req.auth, user: afterLoginUser },
|
||||||
afterLoginUser,
|
afterLoginUser,
|
||||||
null,
|
null,
|
||||||
req.config
|
req.config,
|
||||||
|
req.info.context
|
||||||
);
|
);
|
||||||
|
|
||||||
if (authDataResponse) {
|
if (authDataResponse) {
|
||||||
|
|||||||
@@ -270,6 +270,8 @@ export function getRequestObject(
|
|||||||
triggerType === Types.afterSave ||
|
triggerType === Types.afterSave ||
|
||||||
triggerType === Types.beforeDelete ||
|
triggerType === Types.beforeDelete ||
|
||||||
triggerType === Types.afterDelete ||
|
triggerType === Types.afterDelete ||
|
||||||
|
triggerType === Types.beforeLogin ||
|
||||||
|
triggerType === Types.afterLogin ||
|
||||||
triggerType === Types.afterFind
|
triggerType === Types.afterFind
|
||||||
) {
|
) {
|
||||||
// Set a copy of the context on the request object.
|
// Set a copy of the context on the request object.
|
||||||
|
|||||||
Reference in New Issue
Block a user