From cb39714650ce21af5fb066c1ffdc8049a9a2ac77 Mon Sep 17 00:00:00 2001 From: Jiasheng Date: Wed, 11 Dec 2024 19:40:06 +0800 Subject: [PATCH 1/2] Update auth0.md --- docs/guides/authentication/auth0.md | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/docs/guides/authentication/auth0.md b/docs/guides/authentication/auth0.md index d8f53cdf..1edb2751 100644 --- a/docs/guides/authentication/auth0.md +++ b/docs/guides/authentication/auth0.md @@ -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 @@ -134,26 +133,26 @@ import { useAuth0 } from "@auth0/auth0-react"; const Profile = () => { const { user, isAuthenticated, isLoading } = useAuth0(); - const { trigger, isMutating } = useCreateUser(); const createUser = useCallback(async (event: FormEvent) => { 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', + body: JSON.stringify({ + id: user.sub, + name: name, + }), + }); + } catch(error){...} return }; ``` - - -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: From 095ad0fbb57a3fe6203a3c26d0a7ada8f9078963 Mon Sep 17 00:00:00 2001 From: Jiasheng Date: Wed, 11 Dec 2024 19:45:17 +0800 Subject: [PATCH 2/2] Update auth0.md --- docs/guides/authentication/auth0.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/guides/authentication/auth0.md b/docs/guides/authentication/auth0.md index 1edb2751..9d790932 100644 --- a/docs/guides/authentication/auth0.md +++ b/docs/guides/authentication/auth0.md @@ -142,6 +142,9 @@ const Profile = () => { // create a new user await fetch('/api/create-user', { method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, body: JSON.stringify({ id: user.sub, name: name,