Description
Package containing the bug
next-drupal (NPM package)
Describe the bug
Hello,
I'm not familiar with creating issues, so sorry if I'm not giving every details needed.
I started a new project from scratch by using Next.js 15 with App Router.
In this project, I'd set up next-drupal to use with my CMS, which is already used by the V1 on my app (on Next.js 13 with Pages router).
At first, I tried using the next-drupal package to see if all the requests were working properly, but after setting up my dynamic header and footer, using drupal.getMenu(), I started having 401 errors on the requests.
It took me time before figuring out that I needed to clear my Next.js cache to make everything working again.
In my CMS, I made a OAuth setup just like its described in the next-drupal documentation, this setup was made with the V1.
After a few more hours of thinking and tests, I now understood that the problem comes from the association of the last releases of Next.js with the next-drupal package.
My token expiration is set up at 300 seconds (5 mins), and every time I clear my Next.js cache, I have 5 minutes from my first request without any 401.
I think the problem is that Next.js cache the token given by Drupal at the first request, then try to reuse this token.
I could temporary resolve my problem by adding withCache: false
to my requests, by example:
/**
* Get header main menu data.
*
* @returns {Promise<DrupalMenu>}
*/
export const getHeaderMainMenu = async (): Promise<DrupalMenu> => {
return await drupal.getMenu('main', {
withAuth: true,
withCache: false,
params: {
include: 'field_guide_file,field_guide_image',
'fields[menu_link_content--main]': 'title,url,parent,field_guide_file,field_guide_image',
'fields[file--file]': 'uri',
},
})
}
But I think that this will be bad using it on every requests I make with the DrupalClient.
Is it possible to fix it with my informations, or need I to provide more ?