How to get user profile structure after login/signup. Fields such as created_at, last_login, user_id

I have a React application and have Auth0 working with it for signing up, logging in, and logging off. Everything works fine. All the state information updates as expected as the async calls are made. Eventually a user object is returned and it has the correct information. The auth0Client returns a user object that contains very little information. It contains fields like this:

  1. email: “someEmail@gmail.com
  2. email_verified: true
  3. name: “someEmail@gmail.com
  4. nickname: “someNickName”
  5. picture: “someUrl”
  6. sub: “auth0|5ef6a94271fd3c0013b8b58c”
  7. updated_at: “2020-07-16T04:50:10.669Z”

The documentation says this is a standardized user object that only contains these fields. How do I get all the other fields described in the “User Profile Structure” document? Fields such as created_at?

Looking around the documentation on the website I started looking at using “Rules” to add the data, but that didn’t seem right. The user object coming into the Rules didn’t have the information anyway. Am I supposed to make another call to some other API to get the more “complete” user record?

I assume this is a very basic question with a simple answer. All the other information with the tutorials worked fine.

Hi @sfordjasiri ,

Welcome to the Community!

You can add as many details of user as you want using custom claims. Please refer to below topic and let us know if your query resolved.

How to add custom user claim to access token for API? (Authorization Code Grant)

Sorry, I am not understanding where or how this is done. Is the a Rule I write on the Auth0 management dashboard? Is this client side code? Does this have anything to do with putting code into “Rules”? On my client side, I am using the React SPA tutorial. In my Auth0Provider I have called createAuth0Client(), and eventually I call getUser() to get the user. But, as I said in my initial question, the user that is returned does not contain all the information I want, such as created_at, user_id, etc.

I am not understanding what the people are talking about when they “add custom user claim to access token”, or what that has to do with getting the other user information.

Please note, I have only just started using Auth0 and have only run through the tutorials about using it with React by creating a Auth0Provider, so the thread you pointed to either doesn’t apply, or I my knowledge is too limited to see how it is used. For example, I don’t even understand whether I need to write client side or Auth0 Rule code to do what it talks about.

You need a add a rule and inside that rule you can add custom claims to add as many users details in token as you want.

I think what you and the assorted documentation is telling me is that I CANNOT add the created_at field to the user object.

I think what you and the assorted documentation is telling me is that in the Rule I need to add the created_at field to the context.accessToken.

Let’s assume that is true. But while in the Rule, the user object passed to the Rule function does not have a created_at field. I am not understanding where that information is available to the Rule function. This is what a user looks like in the Auth0 test area:

{ name: ‘jdoe@foobar.com’,
email: ‘jdoe@foobar.com’,
user_id: ‘auth0|0123456789’,
nickname: ‘jdoe’,
picture: ‘http://foobar.com/pictures/jdoe.png’,
identities:
[ { provider: ‘auth0’,
user_id: ‘0123456789’,
connection: ‘Username-Password-Connection’,
isSocial: false } ],
persistent: {} }

I appreciate the help, but at this point I think I just don’t have the knowledge to even understand what you are telling me. I’ll take a look on Github and see if there is an example there that delivers any of the user object properties such as created_at, family_name, given_name, phone_number, etc., to a client.

In rule you simply need to get created_at fields using “user.created_at” . See below link for all the details you can have and fetch against user object. Everything is clearly mention in the documentations.
Let us know if it helps.

The Auth0 Doc you mention is one of the first docs I read. But, as I have said, I am not seeing those properties in the user object in the Rule or on the client side. If I write a Rule like this:

I do not see any properties I added in my Rule in the idTokenClaims or user objects I get in my React application on the client side:

I am not sure if I need to do something to tell an application to use a particular Rule. The on/off slider is on (green) so I am assuming it is being applied.

Thanks for you help, but I don’t want to take up any more of your time. I obviously do not understand how to use the Auth0 software. I previously wrote a Node.JS REST server that does authentication, keeps a MongoDB of users, and hands the client a JWT, and I can just stick with that if I do not figure this out.

Thanks for your help, but please do not spend any more of your time on this.

You need to add a namespace to your rule:

function (user, context, callback) {
  var namespace = "https://leanangle.io/claims/";
  context.idToken[namespace + "created_at"] = user.created_at;
  callback(null, user, context);
}

See also this example rule:

1 Like

Thanks for sharing that @markd!

Thanks for your help. I finally figured it out. Most of my confusion was caused by the fact that the Rules do not work the same way using the “TRY THIS RULE” simulator as they work in production. So, I was trying things in the simulator that should work, but did not. Also, I was doing things in the simulator that worked in the simulator, but did not work in production. This caused me no end of confusion.

For example, most of the user values described in the documentation are undefined when run in the simulator. If the Rule has this line:

console.log(user.created_at);

the simulator prints out “undefined”. So, that is why I kept asking where I could get the user.created_at value. This would not work in the simulator:

context.idToken[“http://something.com/someProperty”] = user.created_at;

But, in production, the user.created_at exists, and this works.

The namespace issue… In the simulator, you don’t need a namespace. For example, this works in the simulator:

context.idToken.property4 = “someValue4”;

but does not work in production.

The namespace can be something as short as “http:” and it works fine. For example:

context.idToken[“http:someProperty”]= “someValue”;

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.