Overview
When a user signs up to our service using an external authorisation provider such as Google or Facebook then the users name is stored as you’d expect in the Auth0 ‘name’ field. However, when a user signs up using their email address, their email address is stored in the ‘name’ field.
We want the users real name to always be in the ‘name’ field, for easy integration with other 3rd party services.
Research
From the docs: https://auth0.com/docs/metadata
Auth0 allows you to store metadata, or data related to each user that
has not come from the identity provider. There are two kinds of
metadata:user_metadata: stores user attributes (such as user preferences) that
do not impact a user’s core functionality; app_metadata: stores
information (such as a user’s support plan, security roles, or access
control groups) that can impact a user’s core functionality, such as
how an application functions or what the user can access.
So, we can store the user’s name in the metadata and then retrieve it when Auth0 returns the profile. This isn’t ideal though as it adds unnecessary complexity.
A question from the official forums:
https://auth0.com/forum/t/editing-user-name/2944
The user asks:
If I’m storing users in Auth0’s database, is it really not possible to
set their real-world names? It seems like it only accepts email
address.
And gets the response:
It’s possible to store this or any other information under
app_metadata or user_metadata. You can modify this information through
the dashboard, rules or the API:
https://auth0.com/docs/api/management/v2#!/Users/patch_users_by_id
Basically, there doesn’t seem to be anywhere in the documentation or on the forum on how to solve this issue.
We did finally come up with a way to have the user’s real name be returned with the user profile. I have posted the answer here to make life for other devs a bit easier if encountering this issue.
2
Answers
Solution
Basically, if you add a 'name' property to the app_metadata for the user, then Auth0 will use that value as the user's name, both on the dashboard and when returning the user's profile via a GET request.
Example JSON:
I believe the first name and last name has ben depreciated, apart from core authentication fields on the user, add custom systematic/core metadata to app_metadata and store all other related data in user_metadata, e.g. first name and lastname. I do this and then just have a property that concatenates these for a FullName property.