Next.js Discord

Discord Forum

Unable to get User data from supabase with cookies in API routes?

Unanswered
Gharial posted this in #help-forum
Open in Discord
GharialOP
I'm having trouble getting users data in an API route. In fact, I'm not even sure if getting cookies in API routes are the same as getting cookies in my other pages or components

typically i would get information:

import { createClient } from "@/lib/supabase/server";
import { cookies } from "next/headers";

export default async function Home() {
  const cookieStore = cookies();
  const supabase = createClient(cookieStore);
  const { data: { user } } = await supabase.auth.getUser();
...


This would give me data, but when I do this within an api/image/webhook/route.ts (api route)

export async function POST(req: NextRequest, res: NextResponse) {
  const cookieStore = cookies();
  console.log("cookieStore in webhook", cookieStore);
  const supabase = createClient(cookieStore);
  ...


its as if there's no cookies set. user becomes null, and even when i console log the cookie store, its not the same as if it were console logged in my Home component.

1 Reply

GharialOP
i think i see the issue, it looks like because i'm using webhooks and ngrok as the webook url, it doesn't have any stored cookies there. how would I go about handling this?