Skip to content

Commit cb39714

Browse files
authored
Update auth0.md
1 parent 261a814 commit cb39714

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

docs/guides/authentication/auth0.md

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,7 @@ You can add what you need to this variable and set the types for it as referred
8282
8383
You may want to keep a record of User's in your own database.
8484
85-
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.
86-
85+
When a user doesn't exist in your database, your application can trigger an onboarding flow to create one:
8786
```ts
8887
const currentUser = async (req) => {
8988
// Get your auth0 auth session
@@ -134,26 +133,26 @@ import { useAuth0 } from "@auth0/auth0-react";
134133

135134
const Profile = () => {
136135
const { user, isAuthenticated, isLoading } = useAuth0();
137-
const { trigger, isMutating } = useCreateUser();
138136

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

143-
await trigger({
144-
data: {
145-
id: user.sub,
146-
name: name,
147-
},
148-
});
149-
}, [trigger, user])
141+
try {
142+
// create a new user
143+
await fetch('/api/create-user', {
144+
method: 'POST',
145+
body: JSON.stringify({
146+
id: user.sub,
147+
name: name,
148+
}),
149+
});
150+
} catch(error){...}
150151

151152
return <UserForm onSubmit={createUser}/>
152153
};
153154
```
154-
155-
156-
When the client is created, the database is queried using the contents of the Auth0 token.
155+
After this, the user id stored in your database is the same with Auth0 identifier.
157156

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

0 commit comments

Comments
 (0)