@@ -202,113 +202,113 @@ export class UsersRouter extends ClassesRouter {
202
202
try {
203
203
const user = await this . _authenticateUserFromRequest ( req ) ;
204
204
const authData = req . body && req . body . authData ;
205
- // Check if user has provided their required auth providers
206
- Auth . checkIfUserHasProvidedConfiguredProvidersForLogin (
207
- req ,
208
- authData ,
209
- user . authData ,
210
- req . config
211
- ) ;
212
-
213
- let authDataResponse ;
214
- let validatedAuthData ;
215
- if ( authData ) {
216
- const res = await Auth . handleAuthDataValidation (
205
+ // Check if user has provided their required auth providers
206
+ Auth . checkIfUserHasProvidedConfiguredProvidersForLogin (
207
+ req ,
217
208
authData ,
218
- new RestWrite (
219
- req . config ,
220
- req . auth ,
221
- '_User' ,
222
- { objectId : user . objectId } ,
223
- req . body || { } ,
224
- user ,
225
- req . info . clientSDK ,
226
- req . info . context
227
- ) ,
228
- user
209
+ user . authData ,
210
+ req . config
229
211
) ;
230
- authDataResponse = res . authDataResponse ;
231
- validatedAuthData = res . authData ;
232
- }
233
212
234
- // handle password expiry policy
235
- if ( req . config . passwordPolicy && req . config . passwordPolicy . maxPasswordAge ) {
236
- let changedAt = user . _password_changed_at ;
213
+ let authDataResponse ;
214
+ let validatedAuthData ;
215
+ if ( authData ) {
216
+ const res = await Auth . handleAuthDataValidation (
217
+ authData ,
218
+ new RestWrite (
219
+ req . config ,
220
+ req . auth ,
221
+ '_User' ,
222
+ { objectId : user . objectId } ,
223
+ req . body || { } ,
224
+ user ,
225
+ req . info . clientSDK ,
226
+ req . info . context
227
+ ) ,
228
+ user
229
+ ) ;
230
+ authDataResponse = res . authDataResponse ;
231
+ validatedAuthData = res . authData ;
232
+ }
237
233
238
- if ( ! changedAt ) {
234
+ // handle password expiry policy
235
+ if ( req . config . passwordPolicy && req . config . passwordPolicy . maxPasswordAge ) {
236
+ let changedAt = user . _password_changed_at ;
237
+
238
+ if ( ! changedAt ) {
239
239
// password was created before expiry policy was enabled.
240
240
// simply update _User object so that it will start enforcing from now
241
- changedAt = new Date ( ) ;
242
- req . config . database . update (
243
- '_User' ,
244
- { username : user . username } ,
245
- { _password_changed_at : Parse . _encode ( changedAt ) }
246
- ) ;
247
- } else {
241
+ changedAt = new Date ( ) ;
242
+ req . config . database . update (
243
+ '_User' ,
244
+ { username : user . username } ,
245
+ { _password_changed_at : Parse . _encode ( changedAt ) }
246
+ ) ;
247
+ } else {
248
248
// check whether the password has expired
249
- if ( changedAt . __type == 'Date' ) {
250
- changedAt = new Date ( changedAt . iso ) ;
249
+ if ( changedAt . __type == 'Date' ) {
250
+ changedAt = new Date ( changedAt . iso ) ;
251
+ }
252
+ // Calculate the expiry time.
253
+ const expiresAt = new Date (
254
+ changedAt . getTime ( ) + 86400000 * req . config . passwordPolicy . maxPasswordAge
255
+ ) ;
256
+ if ( expiresAt < new Date ( ) )
257
+ // fail of current time is past password expiry time
258
+ { throw new Parse . Error (
259
+ Parse . Error . OBJECT_NOT_FOUND ,
260
+ 'Your password has expired. Please reset your password.'
261
+ ) ; }
251
262
}
252
- // Calculate the expiry time.
253
- const expiresAt = new Date (
254
- changedAt . getTime ( ) + 86400000 * req . config . passwordPolicy . maxPasswordAge
255
- ) ;
256
- if ( expiresAt < new Date ( ) )
257
- // fail of current time is past password expiry time
258
- { throw new Parse . Error (
259
- Parse . Error . OBJECT_NOT_FOUND ,
260
- 'Your password has expired. Please reset your password.'
261
- ) ; }
262
263
}
263
- }
264
264
265
- // Remove hidden properties.
266
- UsersRouter . removeHiddenProperties ( user ) ;
267
-
268
- await req . config . filesController . expandFilesInObject ( req . config , user ) ;
269
-
270
- // Before login trigger; throws if failure
271
- await maybeRunTrigger (
272
- TriggerTypes . beforeLogin ,
273
- req . auth ,
274
- Parse . User . fromJSON ( Object . assign ( { className : '_User' } , user ) ) ,
275
- null ,
276
- req . config ,
277
- req . info . context
278
- ) ;
279
-
280
- // If we have some new validated authData update directly
281
- if ( validatedAuthData && Object . keys ( validatedAuthData ) . length ) {
282
- await req . config . database . update (
283
- '_User' ,
284
- { objectId : user . objectId } ,
285
- { authData : validatedAuthData } ,
286
- { }
265
+ // Remove hidden properties.
266
+ UsersRouter . removeHiddenProperties ( user ) ;
267
+
268
+ await req . config . filesController . expandFilesInObject ( req . config , user ) ;
269
+
270
+ // Before login trigger; throws if failure
271
+ await maybeRunTrigger (
272
+ TriggerTypes . beforeLogin ,
273
+ req . auth ,
274
+ Parse . User . fromJSON ( Object . assign ( { className : '_User' } , user ) ) ,
275
+ null ,
276
+ req . config ,
277
+ req . info . context
287
278
) ;
288
- }
289
279
290
- const { sessionData, createSession } = RestWrite . createSession ( req . config , {
291
- userId : user . objectId ,
292
- createdWith : {
293
- action : 'login' ,
294
- authProvider : 'password' ,
295
- } ,
296
- installationId : req . info . installationId ,
297
- } ) ;
280
+ // If we have some new validated authData update directly
281
+ if ( validatedAuthData && Object . keys ( validatedAuthData ) . length ) {
282
+ await req . config . database . update (
283
+ '_User' ,
284
+ { objectId : user . objectId } ,
285
+ { authData : validatedAuthData } ,
286
+ { }
287
+ ) ;
288
+ }
289
+
290
+ const { sessionData, createSession } = RestWrite . createSession ( req . config , {
291
+ userId : user . objectId ,
292
+ createdWith : {
293
+ action : 'login' ,
294
+ authProvider : 'password' ,
295
+ } ,
296
+ installationId : req . info . installationId ,
297
+ } ) ;
298
298
299
- user . sessionToken = sessionData . sessionToken ;
299
+ user . sessionToken = sessionData . sessionToken ;
300
300
301
- await createSession ( ) ;
301
+ await createSession ( ) ;
302
302
303
- const afterLoginUser = Parse . User . fromJSON ( Object . assign ( { className : '_User' } , user ) ) ;
304
- await maybeRunTrigger (
305
- TriggerTypes . afterLogin ,
306
- { ...req . auth , user : afterLoginUser } ,
307
- afterLoginUser ,
308
- null ,
309
- req . config ,
310
- req . info . context
311
- ) ;
303
+ const afterLoginUser = Parse . User . fromJSON ( Object . assign ( { className : '_User' } , user ) ) ;
304
+ await maybeRunTrigger (
305
+ TriggerTypes . afterLogin ,
306
+ { ...req . auth , user : afterLoginUser } ,
307
+ afterLoginUser ,
308
+ null ,
309
+ req . config ,
310
+ req . info . context
311
+ ) ;
312
312
313
313
if ( authDataResponse ) {
314
314
user . authDataResponse = authDataResponse ;
0 commit comments