Skip to content

Commit 217df3e

Browse files
committed
feat: rule to check onboarding checklist
1 parent 5e16e0f commit 217df3e

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
function (user, context, callback) {
2+
if (context.clientID === configuration.CLIENT_ACCOUNTS_LOGIN) {
3+
if (context.redirect) {
4+
return callback(null, user, context);
5+
}
6+
7+
let handle = _.get(user, "handle", null);
8+
const provider = _.get(user, "identities[0].provider", null);
9+
if (!handle && provider === "auth0") {
10+
handle = _.get(user, "nickname", null);
11+
}
12+
console.log("Fetch onboarding_checklist for email/handle: ", user.email, handle, provider);
13+
14+
global.AUTH0_CLAIM_NAMESPACE = "https://" + configuration.DOMAIN + "/";
15+
try {
16+
const axios = require('axios@0.19.2');
17+
18+
const redirectUrl = `https://platform.${configuration.DOMAIN}/onboard`;
19+
const options = {
20+
method: 'GET',
21+
url: `https://api.${configuration.DOMAIN}/v5/members/${handle}/traits?traitIds=onboarding_checklist`,
22+
}
23+
24+
axios(options).then(result => {
25+
const data = result.data;
26+
27+
if (data.length === 0) {
28+
context.redirect = {
29+
url: redirectUrl
30+
}
31+
console.log('Setting redirectUrl', redirectUrl);
32+
return callback(null, user, context);
33+
}
34+
35+
const onboardingChecklistTrait = data.filter((item) => item.traitId === 'onboarding_checklist')[0].traits;
36+
37+
for (let checklistTrait of onboardingChecklistTrait.data) {
38+
if (
39+
checklistTrait.onboarding_wizard != null &&
40+
(checklistTrait.onboarding_wizard.status != null ||
41+
checklistTrait.onboarding_wizard.skip)
42+
) {
43+
return callback(null, user, context);
44+
}
45+
}
46+
47+
const profileCompletedData = onboardingChecklistTrait.data[0].profile_completed;
48+
49+
if (profileCompletedData) {
50+
if (profileCompletedData.status === "completed") {
51+
return callback(null, user, context);
52+
}
53+
54+
for (const item in profileCompletedData.metadata) {
55+
console.log('checking item', item);
56+
if (profileCompletedData.metadata[item]) {
57+
return callback(null, user, context);
58+
}
59+
}
60+
}
61+
62+
context.redirect = {
63+
url: redirectUrl
64+
}
65+
console.log('Setting redirectUrl', redirectUrl);
66+
return callback(null, user, context);
67+
})
68+
69+
} catch (err) {
70+
console.log("Error in fetching onboarding_checklist", + err);
71+
return callback(null, user, context);
72+
}
73+
} else {
74+
return callback(null, user, context);
75+
}
76+
}

0 commit comments

Comments
 (0)