Next.js Discord

Discord Forum

next auth help

Unanswered
Mallow bee posted this in #help-forum
Open in Discord
Mallow beeOP
So when i try to fetch /api/user/guilds its says im not logged in when FETCHING but when i go to the route it works fine.
page.js
  const session = await getServerSession()
  if (!session) return redirect("/")

;

  const guilds = await fetch(`${process.env.NEXTAUTH_URL}/api/user/guilds`, {
    credentials: "include",
  })
  console.log(guilds.statusText);
  if (!guilds.ok) return redirect("/?error=fetching_guilds")
  const guildsJson = await guilds.json()

route.js
export async function GET(req) {
    const session = await getServerSession({ req });
    if (!session) return NextResponse.json({ error: "Unauthorized" }, { status: 401, statusText: "Unauthorized" });

0 Replies