File tree Expand file tree Collapse file tree 4 files changed +38
-4
lines changed Expand file tree Collapse file tree 4 files changed +38
-4
lines changed Original file line number Diff line number Diff 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' ) ;
Original file line number Diff line number Diff 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 ( {
Original file line number Diff line number Diff 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 ) {
Original file line number Diff line number Diff 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.
You can’t perform that action at this time.
0 commit comments