getting user in callback, set dev audience in env

This commit is contained in:
Carter 2024-10-28 18:26:39 -06:00
parent ac7ee6881a
commit 864b7b0689
2 changed files with 13 additions and 11 deletions

2
.env
View file

@ -2,5 +2,5 @@ VITE_APP_API_URL=https://bxt-dev.api.adaptiveagriculture.ca/v1
#Auth0 #Auth0
VITE_AUTH0_CLIENT_DOMAIN=brandxtech.auth0.com 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 VITE_AUTH0_BXT_CLIENT_ID=dzJTpqIeMA4Rwk4xujtwPbAO3TY32bM1

View file

@ -1,4 +1,4 @@
import { useEffect, useState } from 'react' import { useCallback, useEffect, useRef, useState } from 'react'
import reactLogo from '../assets/react.svg' import reactLogo from '../assets/react.svg'
import viteLogo from '/vite.svg' import viteLogo from '/vite.svg'
import './App.css' import './App.css'
@ -11,25 +11,27 @@ function App() {
const [loading, setLoading] = useState(false) const [loading, setLoading] = useState(false)
const userAPI = useUserAPI(); const userAPI = useUserAPI();
const useAuth = useAuth0(); const useAuth = useAuth0();
const hasFetched = useRef(false);
let user_id = or(useAuth.user?.sub, "") let user_id = or(useAuth.user?.sub, "")
// console.log("User ID: ", user_id)
// if (user_id.length > 1) { const loadUser = useCallback(() => {
// if (loading) return;
// userAPI.getUser(user_id).then(resp => { if (hasFetched.current) return;
// console.log(resp)
// })
// }
useEffect(() => {
if (loading) return;
setLoading(true) setLoading(true)
console.log("send")
userAPI.getUser(user_id).then(resp => { userAPI.getUser(user_id).then(resp => {
console.log(resp) console.log(resp)
}).finally(() => { }).finally(() => {
setLoading(false) setLoading(false)
hasFetched.current = true;
}) })
}, []) }, [])
useEffect(() => {
if (loading) return;
loadUser()
}, [loading])
return ( return (
<><div> <><div>