Skip to content

Commit 9e9bc41

Browse files
authored
Merge branch 'alpha' into fix/extension-fix
2 parents 884512d + 39a91d0 commit 9e9bc41

File tree

7 files changed

+47
-7
lines changed

7 files changed

+47
-7
lines changed

changelogs/CHANGELOG_alpha.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# [6.4.0-alpha.1](https://github.com/parse-community/parse-server/compare/6.3.0...6.4.0-alpha.1) (2023-09-20)
2+
3+
### Features
4+
5+
* Add context to Cloud Code Triggers `beforeLogin` and `afterLogin` ([#8724](https://github.com/parse-community/parse-server/issues/8724)) ([a9c34ef](https://github.com/parse-community/parse-server/commit/a9c34ef1e2c78a42fb8b5fa8d569b7677c74919d))
6+
17
# [6.3.0-alpha.9](https://github.com/parse-community/parse-server/compare/6.3.0-alpha.8...6.3.0-alpha.9) (2023-09-13)
28

39

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "parse-server",
3-
"version": "6.4.0-beta.1",
3+
"version": "6.4.0-alpha.1",
44
"description": "An express module providing a Parse-compatible API server",
55
"main": "lib/index.js",
66
"repository": {

spec/CloudCode.spec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -3327,7 +3327,7 @@ describe('beforeLogin hook', () => {
33273327
expect(req.headers).toBeDefined();
33283328
expect(req.ip).toBeDefined();
33293329
expect(req.installationId).toBeDefined();
3330-
expect(req.context).toBeUndefined();
3330+
expect(req.context).toBeDefined();
33313331
});
33323332

33333333
await Parse.User.signUp('tupac', 'shakur');
@@ -3444,7 +3444,7 @@ describe('afterLogin hook', () => {
34443444
expect(req.headers).toBeDefined();
34453445
expect(req.ip).toBeDefined();
34463446
expect(req.installationId).toBeDefined();
3447-
expect(req.context).toBeUndefined();
3447+
expect(req.context).toBeDefined();
34483448
});
34493449

34503450
await Parse.User.signUp('testuser', 'p@ssword');

spec/ParseUser.spec.js

+30
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,36 @@ describe('Parse.User testing', () => {
107107
}
108108
});
109109

110+
it('user login with context', async () => {
111+
let hit = 0;
112+
const context = { foo: 'bar' };
113+
Parse.Cloud.beforeLogin(req => {
114+
expect(req.context).toEqual(context);
115+
hit++;
116+
});
117+
Parse.Cloud.afterLogin(req => {
118+
expect(req.context).toEqual(context);
119+
hit++;
120+
});
121+
await Parse.User.signUp('asdf', 'zxcv');
122+
await request({
123+
method: 'POST',
124+
url: 'http://localhost:8378/1/login',
125+
headers: {
126+
'X-Parse-Application-Id': Parse.applicationId,
127+
'X-Parse-REST-API-Key': 'rest',
128+
'X-Parse-Cloud-Context': JSON.stringify(context),
129+
'Content-Type': 'application/json',
130+
},
131+
body: {
132+
_method: 'GET',
133+
username: 'asdf',
134+
password: 'zxcv',
135+
},
136+
});
137+
expect(hit).toBe(2);
138+
});
139+
110140
it('user login with non-string username with REST API', async done => {
111141
await Parse.User.signUp('asdf', 'zxcv');
112142
request({

src/Routers/UsersRouter.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,8 @@ export class UsersRouter extends ClassesRouter {
259259
req.auth,
260260
Parse.User.fromJSON(Object.assign({ className: '_User' }, user)),
261261
null,
262-
req.config
262+
req.config,
263+
req.info.context
263264
);
264265

265266
// If we have some new validated authData update directly
@@ -291,7 +292,8 @@ export class UsersRouter extends ClassesRouter {
291292
{ ...req.auth, user: afterLoginUser },
292293
afterLoginUser,
293294
null,
294-
req.config
295+
req.config,
296+
req.info.context
295297
);
296298

297299
if (authDataResponse) {

src/triggers.js

+2
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,8 @@ export function getRequestObject(
270270
triggerType === Types.afterSave ||
271271
triggerType === Types.beforeDelete ||
272272
triggerType === Types.afterDelete ||
273+
triggerType === Types.beforeLogin ||
274+
triggerType === Types.afterLogin ||
273275
triggerType === Types.afterFind
274276
) {
275277
// Set a copy of the context on the request object.

0 commit comments

Comments
 (0)