Skip to content

Conversation

@jeobrien
Copy link
Contributor

@jeobrien jeobrien commented Dec 12, 2017

This adds a UserData class to the Node client, which is exposed through the client like so:

const { UserData } = require('intercom-client');
const settings = {
  verificationSecret: 'abc123',
  app_id: 'xyz789',
  user_id: 1,
  email: 'jess@intercom.io',
  name: 'Jess OBrien',
  company: {
    id: 123,
    name: 'Intercom'
  }
};
const userData = new UserData(settings);
res.send(userData.json());

It returns an escaped json object, including the user_hash required for Identity Verification. You can call window.Intercom(boot) on the client side with the data returned.

}
getVerificationSecret() {
const { verificationSecret } = this.settings;
delete this.settings.verificationSecret;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're going to delete the secret, we should ensure json can be called multiple times by skipping setUserHash if user_hash is already set in this.settings

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated!

lib/user-data.js Outdated
this.settings = settings;
}
json() {
const verificationSecret = this.getVerificationSecret();
Copy link

@kmiyashiro kmiyashiro Dec 12, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might also want to wrap the secret/hash things in a conditional and skip them if this.loggedOut

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am skipping the hash already if logged out here: https://github.com/intercom/intercom-node/pull/173/files#diff-4c919967cdaa500e061ab2489c6d0136R38

Do you think we should also skip the verification secret?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it seems like we should skip this work if this.loggedOut || this.settings.user_hash. Since verificationSecret and identifier are only used in setUserHash in json, and getVerificationSecret/getIdentifier are sibling methods, you could move those getters to be called inside setUserHash as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great point

@jeobrien jeobrien merged commit 4bd0497 into master Dec 15, 2017
@jeobrien jeobrien deleted the jess/user-data branch December 15, 2017 19:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants