dsds
dsds

Reputation: 185

Auth0: How to add custom properties to UserObject?

Hello dear StackOverFlow community, i don't know much about Auth0 and need help. And I wonder how to add my own properties when creating a user? just for info i have connected Auth0 to my own MongoDB atlas database.

i want to add a customId when creating a user, and this should be a 16-digit random number.

And my userObj should then look something like this:

{
_id: ObjectId("5f720126054c87001662a138"),
connection:"MongoDB"
client_id:"zoClZ3gZE56iwblHXQ1vgwEcLfYr81Bx"
email:"[email protected]"
username:"gustek"
password:"$2b$10$dE69gGsDqVfWtmnXZ6EaKetILUmEju8N9PVjtDpgzzAp4jYNQbe8G"
tenant:"dev-test"
email_verified:false
customId:"9829539769841530"
}

I mean I found something in the documentation but I do not know how to implement it: https://auth0.com/docs/users/set-metadata-properties-on-creation

Do I have to do it over this surface?

enter image description here

As I said before, I have no idea how I could achieve this. I am grateful for every answer!

Upvotes: 0

Views: 737

Answers (1)

Dan Woda
Dan Woda

Reputation: 668

You can use an app_metadata property in the user object to store data that is not part of the normalized user profile. This would include a custom UUID like you described here.

The user object would look like this:

{
    client_id: "<ID of creating client (application)>",
    tenant: "<name of creating Auth0 tenant>",
    email: "<email address for the user>",
    password: "<password for the user>",
    username: "<name associated with the user>",
    user_metadata: {
        "language": "en"
    },
    app_metadata: {
        "custom_id": "1234567890"
    }
}

While user_metadata and app_metadata are optional, if supplied, they do not need to be stored in the legacy identity store; Auth0 automatically stores these values as part of the user profile record created internally. These values are (optionally) provided as a reference: their contents potentially being influential to legacy identity creation.

Upvotes: 1

Related Questions