Skip to content

Commit

Permalink
Merge pull request #855 from auth0/fix/set-prefill-when-client-is-ini…
Browse files Browse the repository at this point in the history
…tialized

Only set prefill values when client is initialized
  • Loading branch information
hzalaz authored Feb 6, 2017
2 parents 8629c09 + 856b53d commit 9ecc469
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
9 changes: 7 additions & 2 deletions src/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,12 @@ export function setup(id, clientID, domain, options, hookRunner, emitEventFn) {
hashCleanup: options.hashCleanup === false ? false : true,
allowedConnections: Immutable.fromJS(options.allowedConnections || []),
ui: extractUIOptions(id, options),
defaultADUsernameFromEmailPrefix: options.defaultADUsernameFromEmailPrefix === false ? false : true
defaultADUsernameFromEmailPrefix: options.defaultADUsernameFromEmailPrefix === false ? false : true,
prefill: options.prefill || {}
}));

m = i18n.initI18n(m);

return m;
}

Expand Down Expand Up @@ -365,6 +366,10 @@ export function defaultADUsernameFromEmailPrefix(m) {
return get(m, "defaultADUsernameFromEmailPrefix", true);
}

export function prefill(m) {
return get(m, "prefill", {});
}

export function warn(x, str) {
const shouldOutput = Map.isMap(x)
? !ui.disableWarnings(x)
Expand Down
15 changes: 10 additions & 5 deletions src/engine/classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ function validateAllowedConnections(m) {
return m;
}

const setPrefill = m => {
const { email, username } = l.prefill(m).toJS();
if (typeof email === "string") m = setEmail(m, email);
if (typeof username === "string") m = setUsername(m, username, "username", false);
return m;
}

class Classic {

static SCREENS = {
Expand All @@ -111,15 +118,13 @@ class Classic {
model = initDatabase(model, options);
model = initEnterprise(model, options);

const { email, username } = options.prefill || {};
if (typeof email === "string") model = setEmail(model, email);
if (typeof username === "string") model = setUsername(model, username, "username", false);

return model;
}

didReceiveClientSettings(m) {
return validateAllowedConnections(m);
m = validateAllowedConnections(m);
m = setPrefill(m);
return m;
}

willShow(m, opts) {
Expand Down
1 change: 1 addition & 0 deletions support/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
};

const lock = new Auth0Lock(cid, domain, options);
window.lock = lock;

lock.on("authenticated", function(authResult) {
console.log(authResult);
Expand Down

0 comments on commit 9ecc469

Please sign in to comment.