I want to somehow get my return value after getting session.
App.jsx file
import { useEffect, useState } from 'react'
import './App.css'
import {Navigate} from 'react-router-dom'
import { supabase } from './helpers/supabaseClient'
function App() {
const [session, setSession] = useState(null)
useEffect(() => {
supabase.auth.getSession().then(({ data: { session } }) => {
setSession(session)
})
supabase.auth.onAuthStateChange((_event, session) => {
setSession(session)
})
console.log(session);
}, [])
return (
<div className="">
{session ? <Navigate to="/home"></Navigate> : <Navigate to="/account"></Navigate>}
{/* {true ? <Navigate to="/home"></Navigate> : <Navigate to="/account"></Navigate>} */}
</div>
)
}
export default App
The Navigate function routes to another react component before I am able to retrieve session using useEffect. I have tried using await function but that too seems to not work. I used setTimeout(2000). But that didn't work either.
What should be done. I don't prefer to make it a single page application. I want to use Navigate somehow.
Navigate
component regardless of anysession
value. What exactly are you trying to accomplish?