Skip to content

Instantly share code, notes, and snippets.

Last active Dec 24, 2019
What would you like to do?
Auth0 Progressive Profiling Proof-of-concept
<!DOCTYPE html>
<html lang="en-us">
<title>Auth0 Progressive Profiling</title>
max-width: 900px;
margin-left: auto;
margin-right: auto;
display: block;
<h1>Auth0 Progressing Profiling</h1>
<h2>Proof of Concept page</h2>
<form id="submitform" method="POST" action="https://{instance}">
<label>First name
<input name="given_name" required />
<label>Last name
<input name="family_name" required />
<button type="submit">Save Changes</button>
const urlparams = new URLSearchParams(;
const stateval = urlparams.get('state');
const form = document.getElementById('submitform');
form.action = form.action + stateval;
function (user, context, callback) {
const RULE_NAME = 'Progressive Profiling';
console.log(`${RULE_NAME} started.`);
context.clientMetadata = context.clientMetadata || {};
const progprof_url = context.clientMetadata.progressive_profiling_url || configuration.progressive_profiling_url;
// skip if this doesn't need progressive profiling
if (!progprof_url) {
return callback(null, user, context);
user.user_metadata = user.user_metadata || {};
// if returning from the profile site
if (context.protocol === "redirect-callback") {
// build complete user profile
user.user_metadata = Object.assign(user.user_metadata,
['given_name', 'family_name']));
// update user profile in Auth0
auth0.users.updateUserMetadata(user.user_id, user.user_metadata)
.then(() => {
console.log(`${RULE_NAME}: ${user.user_id}: Updated user profile with given_name "${user.user_metadata.given_name}" and family_name "${user.user_metadata.family_name}".`);
callback(null, user, context);
.catch((err) => {
console.log(`${RULE_NAME} ERROR:`, err);
} else {
// check if user already has profiled fields
if (!user.user_metadata || !user.user_metadata.given_name || !user.user_metadata.family_name) {
context.redirect = {
url: progprof_url
console.log(`${RULE_NAME}: Redirecting to ${context.redirect.url}`);
callback(null, user, context);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment