Next.js Discord

Discord Forum

How to fetch data after session conditionals in a client component

Unanswered
Yellowstripe scad posted this in #help-forum
Open in Discord
Yellowstripe scadOP
'use client'
export default function Dashboard() {
    const { data: session, status } = useSession()
    const router = useRouter()

    if (status === 'loading') {
        return <Loading />
    }

    if (!session || status !== 'authenticated') {
        router.push('/login')
        return null
    }


this is a client component, I want to send a GET request to an api in my backend. I want to display the loading until the data is fetched.

0 Replies