convex-auth: convexAuthNextjsToken next.js@v15 vercel production build error
(breaking-change) in next.js v15 u have to await the headers and cookies. i have this function to get the current loged in user:
export async function getCurrentUser_nextjs_use() {
const token = await convexAuthNextjsToken();
if(!token) return null;
const user = await fetchQuery(api.auth.currentUser, {}, {token});
return user
}
im calling this function in server component:
export default async function SuperAdminPage(){
const user = await getCurrentUser_nextjs_use()
if(user?.role !== "super-admin") return unauthorized()
return <div>secret content</div>
}
so the problem when i run npm run build localy everything is fine, but when i build in vercel it shows to me this error :
{
error: Error: Dynamic server usage: Route /super-admin couldn't be rendered statically because it used
headers
. See more info here: https://nextjs.org/docs/messages/dynamic-server-error
at b (.next/server/chunks/579.js:34:38340)
at d (.next/server/chunks/579.js:35:12041)
at l (.next/server/chunks/579.js:35:71708)
at d (.next/server/chunks/579.js:35:71996)
at a (.next/server/chunks/307.js:1:15364)
at c (.next/server/app/super-admin/page.js:1:19272) {
description: "Route /super-admin couldn't be rendered statically because it used headers
. See more info here: https://nextjs.org/docs/messages/dynamic-server-error",
digest: 'DYNAMIC_SERVER_USAGE'
}
}.
so when i visit this page https://nextjs.org/docs/messages/dynamic-server-error. they mention this can happen when u r not awaiting promise and convexAuthNextjsToken function not awaiting headers bcuz it stick to nextjs14 (no awaiting headers). can u fix this pls
1 Reply
This is fixed in convex auth 0.0.75, what version are you using