File tree 4 files changed +38
-4
lines changed
4 files changed +38
-4
lines changed Original file line number Diff line number Diff line change @@ -3327,7 +3327,7 @@ describe('beforeLogin hook', () => {
3327
3327
expect ( req . headers ) . toBeDefined ( ) ;
3328
3328
expect ( req . ip ) . toBeDefined ( ) ;
3329
3329
expect ( req . installationId ) . toBeDefined ( ) ;
3330
- expect ( req . context ) . toBeUndefined ( ) ;
3330
+ expect ( req . context ) . toBeDefined ( ) ;
3331
3331
} ) ;
3332
3332
3333
3333
await Parse . User . signUp ( 'tupac' , 'shakur' ) ;
@@ -3444,7 +3444,7 @@ describe('afterLogin hook', () => {
3444
3444
expect ( req . headers ) . toBeDefined ( ) ;
3445
3445
expect ( req . ip ) . toBeDefined ( ) ;
3446
3446
expect ( req . installationId ) . toBeDefined ( ) ;
3447
- expect ( req . context ) . toBeUndefined ( ) ;
3447
+ expect ( req . context ) . toBeDefined ( ) ;
3448
3448
} ) ;
3449
3449
3450
3450
await Parse . User . signUp ( 'testuser' , 'p@ssword' ) ;
Original file line number Diff line number Diff line change @@ -107,6 +107,36 @@ describe('Parse.User testing', () => {
107
107
}
108
108
} ) ;
109
109
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
+
110
140
it ( 'user login with non-string username with REST API' , async done => {
111
141
await Parse . User . signUp ( 'asdf' , 'zxcv' ) ;
112
142
request ( {
Original file line number Diff line number Diff line change @@ -259,7 +259,8 @@ export class UsersRouter extends ClassesRouter {
259
259
req . auth ,
260
260
Parse . User . fromJSON ( Object . assign ( { className : '_User' } , user ) ) ,
261
261
null ,
262
- req . config
262
+ req . config ,
263
+ req . info . context
263
264
) ;
264
265
265
266
// If we have some new validated authData update directly
@@ -291,7 +292,8 @@ export class UsersRouter extends ClassesRouter {
291
292
{ ...req . auth , user : afterLoginUser } ,
292
293
afterLoginUser ,
293
294
null ,
294
- req . config
295
+ req . config ,
296
+ req . info . context
295
297
) ;
296
298
297
299
if ( authDataResponse ) {
Original file line number Diff line number Diff line change @@ -270,6 +270,8 @@ export function getRequestObject(
270
270
triggerType === Types . afterSave ||
271
271
triggerType === Types . beforeDelete ||
272
272
triggerType === Types . afterDelete ||
273
+ triggerType === Types . beforeLogin ||
274
+ triggerType === Types . afterLogin ||
273
275
triggerType === Types . afterFind
274
276
) {
275
277
// Set a copy of the context on the request object.
You can’t perform that action at this time.
0 commit comments