@@ -930,31 +930,25 @@ RestWrite.prototype.createSessionTokenIfNeeded = async function () {
930
930
if ( this . auth . user && this . data . authData ) {
931
931
return ;
932
932
}
933
- if (
934
- ! this . storage . authProvider && // signup call, with
935
- this . config . preventLoginWithUnverifiedEmail === true && // no login without verification
936
- this . config . verifyUserEmails
937
- ) {
938
- // verification is on
939
- this . storage . rejectSignup = true ;
940
- return ;
941
- }
942
- if ( ! this . storage . authProvider && this . config . verifyUserEmails ) {
943
- let shouldPreventUnverifedLogin = this . config . preventLoginWithUnverifiedEmail ;
944
- if ( typeof this . config . preventLoginWithUnverifiedEmail === 'function' ) {
945
- const { originalObject, updatedObject } = this . buildParseObjects ( ) ;
946
- const request = {
947
- original : originalObject ,
948
- object : updatedObject ,
949
- master : this . auth . isMaster ,
950
- ip : this . config . ip ,
951
- installationId : this . auth . installationId ,
952
- } ;
953
- shouldPreventUnverifedLogin = await Promise . resolve (
954
- this . config . preventLoginWithUnverifiedEmail ( request )
955
- ) ;
956
- }
957
- if ( shouldPreventUnverifedLogin === true ) {
933
+ // If sign-up call
934
+ if ( ! this . storage . authProvider ) {
935
+ // Create request object for verification functions
936
+ const { originalObject, updatedObject } = this . buildParseObjects ( ) ;
937
+ const request = {
938
+ original : originalObject ,
939
+ object : updatedObject ,
940
+ master : this . auth . isMaster ,
941
+ ip : this . config . ip ,
942
+ installationId : this . auth . installationId ,
943
+ } ;
944
+ // Get verification conditions which can be booleans or functions; the purpose of this async/await
945
+ // structure is to avoid unnecessarily executing subsequent functions if previous ones fail in the
946
+ // conditional statement below, as a developer may decide to execute expensive operations in them
947
+ const verifyUserEmails = async ( ) => this . config . verifyUserEmails === true || ( typeof this . config . verifyUserEmails === 'function' && await Promise . resolve ( this . config . verifyUserEmails ( request ) ) === true ) ;
948
+ const preventLoginWithUnverifiedEmail = async ( ) => this . config . preventLoginWithUnverifiedEmail === true || ( typeof this . config . preventLoginWithUnverifiedEmail === 'function' && await Promise . resolve ( this . config . preventLoginWithUnverifiedEmail ( request ) ) === true ) ;
949
+ // If verification is required
950
+ if ( await verifyUserEmails ( ) && await preventLoginWithUnverifiedEmail ( ) ) {
951
+ this . storage . rejectSignup = true ;
958
952
return ;
959
953
}
960
954
}
0 commit comments