Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cached token cause 401 without being refreshed. #822

Open
tomzidani opened this issue Nov 20, 2024 · 1 comment
Open

Cached token cause 401 without being refreshed. #822

tomzidani opened this issue Nov 20, 2024 · 1 comment
Labels
bug Something isn't working triage A new issue that needs triage

Comments

@tomzidani
Copy link

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 ?

@tomzidani tomzidani added bug Something isn't working triage A new issue that needs triage labels Nov 20, 2024
@yobottehg
Copy link
Contributor

This is a duplicate of #788

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage A new issue that needs triage
Projects
None yet
Development

No branches or pull requests

2 participants