cookies().getAll() does not exist
Answered
Asiatic Lion posted this in #help-forum
Asiatic LionOP
Hi, I am following the supabase nextjs setup guide for supbase-ssr, however it seems that cookies.getAll() is not defined
I am using nextjs15 rc and it basically tells me that getAll() does not exist on
https://supabase.com/docs/guides/auth/server-side/nextjs
import { createServerClient, type CookieOptions } from '@supabase/ssr'
import { cookies } from 'next/headers'
export function createClient() {
const cookieStore = cookies()
return createServerClient(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
{
cookies: {
getAll() {
return cookieStore.getAll()
},
setAll(cookiesToSet) {
try {
cookiesToSet.forEach(({ name, value, options }) =>
cookieStore.set(name, value, options)
)
} catch {
// The `setAll` method was called from a Server Component.
// This can be ignored if you have middleware refreshing
// user sessions.
}
},
},
}
)
}I am using nextjs15 rc and it basically tells me that getAll() does not exist on
Promise<ReadonlyRequestCookies> even tho its mentioned in the docshttps://supabase.com/docs/guides/auth/server-side/nextjs
Answered by joulev
cookies is an async function now.const cookieStore = await cookies()which means your
createClient must be async too7 Replies
@Asiatic Lion Hi, I am following the supabase nextjs setup guide for supbase-ssr, however it seems that cookies.getAll() is not defined
import { createServerClient, type CookieOptions } from '@supabase/ssr'
import { cookies } from 'next/headers'
export function createClient() {
const cookieStore = cookies()
return createServerClient(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
{
cookies: {
getAll() {
return cookieStore.getAll()
},
setAll(cookiesToSet) {
try {
cookiesToSet.forEach(({ name, value, options }) =>
cookieStore.set(name, value, options)
)
} catch {
// The `setAll` method was called from a Server Component.
// This can be ignored if you have middleware refreshing
// user sessions.
}
},
},
}
)
}
I am using nextjs15 rc and it basically tells me that getAll() does not exist on `Promise<ReadonlyRequestCookies>` even tho its mentioned in the docs
https://supabase.com/docs/guides/auth/server-side/nextjs
cookies is an async function now.const cookieStore = await cookies()which means your
createClient must be async tooAnswer
@joulev `cookies` is an async function now.
tsx
const cookieStore = await cookies()
which means your `createClient` must be async too
Asiatic LionOP
yep i just figured it out
havent found it in the docs
but then saw that its type Promise
honestly the docs is a mess, it's a combination of next 14 and next 15 stuff, there are some code blocks there that will break in next 14 and some code blocks there that will break in next 15
they used to separate the doc into nextjs.org (14) and rc.nextjs.org (15), now i dont know why they decided to combine them
Asiatic LionOP
i see all good thanks anyways for the fast answer