a cookie property was accessed directly with `cookies().getAll()`. `cookies()` should be awaited
Unanswered
Mini Satin posted this in #help-forum
Mini SatinOP
Hey, I just recently upgraded to next js 15. My project is a standard Nextjs + supabase stack. I know I am getting the error in the utils/supabase/server.ts file but I am not sure how to fix it.
Here is my code:
import { createServerClient } from '@supabase/ssr'
import { cookies, type UnsafeUnwrappedCookies } from 'next/headers';
export function createClient() {
const cookieStore = (cookies() as unknown as UnsafeUnwrappedCookies)
// Create a server's supabase client with newly configured cookie,
// which could be used to maintain user's session
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
// This can be ignored if you have middleware refreshing
// user sessions.
}
},
},
}
)
}
Here is my code:
import { createServerClient } from '@supabase/ssr'
import { cookies, type UnsafeUnwrappedCookies } from 'next/headers';
export function createClient() {
const cookieStore = (cookies() as unknown as UnsafeUnwrappedCookies)
// Create a server's supabase client with newly configured cookie,
// which could be used to maintain user's session
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.
}
},
},
}
)
}
2 Replies
Mini SatinOP
Just to note if i turn the createClient function into async and then await cookies(), it gives me this error:
Error: supabase.from is not a function.
Error: supabase.from is not a function.
Would appreciate it if anyone could help.