From 864b7b0689c5947bc63004ced19c10530ac2af1d Mon Sep 17 00:00:00 2001 From: Carter Date: Mon, 28 Oct 2024 18:26:39 -0600 Subject: [PATCH] getting user in callback, set dev audience in env --- .env | 2 +- src/app/App.tsx | 22 ++++++++++++---------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/.env b/.env index 17ca41e..c131099 100644 --- a/.env +++ b/.env @@ -2,5 +2,5 @@ VITE_APP_API_URL=https://bxt-dev.api.adaptiveagriculture.ca/v1 #Auth0 VITE_AUTH0_CLIENT_DOMAIN=brandxtech.auth0.com -VITE_AUTH0_AUDIENCE=pond.brandxtech.ca +VITE_AUTH0_AUDIENCE=bxt-dev.api.adaptiveagriculture.ca VITE_AUTH0_BXT_CLIENT_ID=dzJTpqIeMA4Rwk4xujtwPbAO3TY32bM1 \ No newline at end of file diff --git a/src/app/App.tsx b/src/app/App.tsx index cb32218..6ec41c4 100644 --- a/src/app/App.tsx +++ b/src/app/App.tsx @@ -1,4 +1,4 @@ -import { useEffect, useState } from 'react' +import { useCallback, useEffect, useRef, useState } from 'react' import reactLogo from '../assets/react.svg' import viteLogo from '/vite.svg' import './App.css' @@ -11,25 +11,27 @@ function App() { const [loading, setLoading] = useState(false) const userAPI = useUserAPI(); const useAuth = useAuth0(); + const hasFetched = useRef(false); let user_id = or(useAuth.user?.sub, "") -// console.log("User ID: ", user_id) -// if (user_id.length > 1) { - -// userAPI.getUser(user_id).then(resp => { -// console.log(resp) -// }) -// } - useEffect(() => { - if (loading) return; + const loadUser = useCallback(() => { + // if (loading) return; + if (hasFetched.current) return; setLoading(true) + console.log("send") userAPI.getUser(user_id).then(resp => { console.log(resp) }).finally(() => { setLoading(false) + hasFetched.current = true; }) }, []) + + useEffect(() => { + if (loading) return; + loadUser() + }, [loading]) return ( <>