Next.js Discord

Discord Forum

fetch not firing

Answered
Brouillard posted this in #help-forum
Open in Discord
I don't understand why the fetch function is not fired at all, I checked in network on my browser inspector:

import React from 'react'
import { getServerSession } from 'next-auth/next'
import { redirect } from 'next/navigation'
const AllEvents = async () => {
  const session = await getServerSession()
  if (!session?.user?.email) redirect("/login")
  const allTheEvents = await fetch(`${process.env.NEXTAUTH_URL}/api/events`, {
    method: 'GET',
    headers: {
      'Content-Type': 'application/json'
    }
  })
  return (
    <div>{ JSON.stringify(allTheEvents) }</div>
  )
}

export default AllEvents
Answered by riský
that looks like server component, and the fetch is done server side
View full answer

3 Replies