1
1
function ( user , context , callback ) {
2
2
if ( context . clientID === configuration . CLIENT_ACCOUNTS_LOGIN ) {
3
3
console . log ( "rule:onboarding-checklist:enter" ) ;
4
- console . log ( "rule:onboarding-checklist:context.request" , context . request ) ;
5
-
6
- if ( context . redirect ) {
4
+
5
+ if ( context . redirect ) {
7
6
console . log ( "rule:onboarding-checklist:exiting due to context being a redirect" ) ;
8
7
return callback ( null , user , context ) ;
9
8
}
@@ -22,16 +21,11 @@ function (user, context, callback) {
22
21
return callback ( null , user , context ) ;
23
22
}
24
23
25
- let handle = _ . get ( user , "handle" , null ) ;
26
- const provider = _ . get ( user , "identities[0].provider" , null ) ;
27
- if ( isSocial || ( ! handle && provider === "auth0" ) ) {
28
- handle = _ . get ( user , "nickname" , null ) ;
29
- }
30
-
31
- console . log ( "rule:onboarding-checklist: fetch onboarding_checklist for email/handle: " , user . email , handle , provider ) ;
24
+ const handle = context . idToken [ global . AUTH0_CLAIM_NAMESPACE + 'handle' ] ;
25
+ console . log ( "rule:onboarding-checklist: fetch onboarding_checklist for email/handle: " , user . email , handle ) ;
32
26
33
- // TODO: Properly fetch handle for social logins
34
- if ( handle == null || isSocial ) {
27
+ if ( handle == null ) {
28
+ console . log ( "rule:onboarding-checklist: exiting due to handle being null." ) ;
35
29
return callback ( null , user , context ) ;
36
30
}
37
31
@@ -111,24 +105,28 @@ function (user, context, callback) {
111
105
112
106
if ( data . length === 0 ) {
113
107
// User doesn't have any traits with traitId onboarding_checklist and should be shown the onboarding wizard
114
- context . idToken [ global . AUTH0_CLAIM_NAMESPACE + 'show_onboarding_wizard ' ] = true ;
115
- console . log ( 'rule:onboarding-checklist:Setting show_onboarding_wizard to true' , user ) ;
108
+ context . idToken [ global . AUTH0_CLAIM_NAMESPACE + 'onboarding_wizard ' ] = 'show' ;
109
+ console . log ( 'rule:onboarding-checklist:Setting onboarding_wizard to show' ) ;
116
110
return callback ( null , user , context ) ;
117
111
}
118
112
119
113
const onboardingChecklistTrait = data . filter ( ( item ) => item . traitId === 'onboarding_checklist' ) [ 0 ] . traits ;
114
+ let override = 'show' ;
120
115
121
116
for ( let checklistTrait of onboardingChecklistTrait . data ) {
122
- if (
123
- checklistTrait . onboarding_wizard != null &&
124
- ( checklistTrait . onboarding_wizard . status != null || // any valid status indicates user has already seen onboarding wizard and needn't be shown again.
125
- checklistTrait . onboarding_wizard . skip ) // for certain signup routes skip is set to true, and thus onboarding wizard needn't be shown
126
- ) {
117
+ if ( checklistTrait . onboarding_wizard != null ) {
118
+ if ( checklistTrait . onboarding_wizard . status !== 'pending_at_user' || // any non pending_at_user status indicates OB was either seen or completed and can be skipped
119
+ checklistTrait . onboarding_wizard . skip || // for certain signup routes skip is set to true, and thus onboarding wizard needn't be shown
120
+ checklistTrait . onboarding_wizard . override === ' skip' )
121
+ {
127
122
return callback ( null , user , context ) ;
123
+ } else if ( checklistTrait . onboarding_wizard . override === 'useRetUrl' ) {
124
+ override = 'useRetUrl' ;
128
125
}
126
+ }
129
127
}
130
-
131
- const profileCompletedData = onboardingChecklistTrait . data [ 0 ] . profile_completed ;
128
+
129
+ const profileCompletedData = onboardingChecklistTrait . data . length > 0 ? onboardingChecklistTrait . data [ 0 ] . profile_completed : null ;
132
130
133
131
if ( profileCompletedData ) {
134
132
if ( profileCompletedData . status === "completed" ) {
@@ -143,8 +141,12 @@ function (user, context, callback) {
143
141
}
144
142
145
143
// All checks failed - indicating user newly registered and needs to be shown the onboarding wizard
146
- console . log ( 'rule:onboarding-checklist: set show_onboarding_wizard' , user ) ;
147
- context . idToken [ global . AUTH0_CLAIM_NAMESPACE + 'show_onboarding_wizard' ] = true ;
144
+ console . log ( 'rule:onboarding-checklist: set onboarding_wizard ' + override ) ;
145
+
146
+ context . idToken [ global . AUTH0_CLAIM_NAMESPACE + 'onboarding_wizard' ] = override ;
147
+
148
+
149
+
148
150
return callback ( null , user , context ) ;
149
151
} catch ( e ) {
150
152
console . log ( "rule:onboarding-checklist:Error in fetching onboarding_checklist" , e ) ;
0 commit comments