Next.js Discord

Discord Forum

nextjs 15 api route problem

Answered
Short mackerel posted this in #help-forum
Open in Discord
Short mackerelOP
Hi guys i got this error i have switch my project from next14 to 15

the only api route i have is this :

import { authOptions } from '@/lib/auth'
import NextAuth from 'next-auth'

const handler = NextAuth(authOptions)

export { handler as GET, handler as POST }



and got this error

GET /api/auth/session 200 in 79ms
[Error: Route "/api/auth/[...nextauth]" used cookies().getAll(). cookies() should be awaited before using its value. Learn more: https://nextjs.org/docs/messages/sync-dynamic-apis]
Error: Route "/api/auth/[...nextauth]" used ...headers() or similar iteration. headers() should be awaited before using its value. Learn more: https://nextjs.org/docs/messages/sync-dynamic-apis
at Function.fromEntries (<anonymous>)
GET /api/auth/session 200 in 78ms
[Error: Route "/api/auth/[...nextauth]" used cookies().getAll(). cookies() should be awaited before using its value. Learn more: https://nextjs.org/docs/messages/sync-dynamic-apis]
Error: Route "/api/auth/[...nextauth]" used ...headers() or similar iteration. headers() should be awaited before using its value. Learn more: https://nextjs.org/docs/messages/sync-dynamic-apis

thanks for your help:pikachu_shocked:
Answered by Asian black bear
You need to update to a newer version of next-auth that supports Next 15 because the header APIs have been changed with v15.
View full answer

3 Replies

Asian black bear
You need to update to a newer version of next-auth that supports Next 15 because the header APIs have been changed with v15.
Answer
Short mackerelOP
okayyyy thanks Near i go try it
all is good thansk dude @Asian black bear ❤️