Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions docs/guides/authentication/auth0.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ You can add what you need to this variable and set the types for it as referred

You may want to keep a record of User's in your own database.

You can create your application in such a way that a lack of the user existing in the managed database triggers a process to create one, such as a user onboarding flow.

When a user doesn't exist in your database, your application can trigger an onboarding flow to create one:
```ts
const currentUser = async (req) => {
// Get your auth0 auth session
Expand Down Expand Up @@ -134,26 +133,29 @@ import { useAuth0 } from "@auth0/auth0-react";

const Profile = () => {
const { user, isAuthenticated, isLoading } = useAuth0();
const { trigger, isMutating } = useCreateUser();

const createUser = useCallback(async (event: FormEvent<HTMLFormElement>) => {
const formData = new FormData(event.currentTarget);
const name = formData.get('name');

await trigger({
data: {
id: user.sub,
name: name,
},
});
}, [trigger, user])
try {
// create a new user
await fetch('/api/create-user', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
id: user.sub,
name: name,
}),
});
} catch(error){...}

return <UserForm onSubmit={createUser}/>
};
```


When the client is created, the database is queried using the contents of the Auth0 token.
After this, the user id stored in your database is the same with Auth0 identifier.

In this case, the Auth type is what provide authentication, not the User model, for example:

Expand Down