oidc-client icon indicating copy to clipboard operation
oidc-client copied to clipboard

Incompatibility with next.js redirects

Open madze opened this issue 2 years ago • 6 comments

Issue

If redirects are configured in a next config the sessions don't seem to make it into session storage, which results in a redirect back to login, which then redirects back to the app - this cycle happens indefinitely.

Steps to reproduce:

  1. Add a new route file (e.g., test.js)

  2. Configure a redirect in a next.js config file (e.g., in a next.config.js file in the root directory):

/** @type {import('next').NextConfig} */
const nextConfig = {
  async redirects() {
    return [
      {
        source: '/',
        destination: '/test',
        permanent: false,
      },
    ]
  },
}

module.exports = nextConfig

Versions

  • react-oidc v6.5.7
  • next v12.2.5
  • react v18.2.0

madze avatar Sep 13 '22 21:09 madze

Hi @madze , thank you very much for your issue. What does look like your oidc configuration?

guillaume-chervet avatar Sep 14 '22 01:09 guillaume-chervet

Hi @guillaume-chervet - Sorry, I should have also mentioned that this was actually using the next.js demo within this repository - So it's the same config that is in there (I just upgraded the react packages):

const configuration = {
  client_id: 'interactive.public.short',
  redirect_uri: 'http://localhost:3001/#authentication/callback',
  silent_redirect_uri: 'http://localhost:3001/#authentication/silent-callback', // Optional activate silent-signin that use cookies between OIDC server and client javascript to restore the session
  scope: 'openid profile email api offline_access',
  authority: 'https://demo.duendesoftware.com'
};

Thank you! Let me know if I can assist further!

madze avatar Sep 14 '22 01:09 madze

Hi @madze , i haven not tested but i think if you update your config like bellow it will work:

const configuration = { client_id: 'interactive.public.short', redirect_uri: 'http://localhost:3001/test/#authentication/callback', silent_redirect_uri: 'http://localhost:3001/test/#authentication/silent-callback', // Optional activate silent-signin that use cookies between OIDC server and client javascript to restore the session scope: 'openid profile email api offline_access', authority: 'https://demo.duendesoftware.com' };

guillaume-chervet avatar Sep 14 '22 09:09 guillaume-chervet

@guillaume-chervet - Thanks!! I just finally had a chance to take a look and though I haven't tested extensively I can verify that this at least works for basic redirects. Also, it seems that this may only be necessary for the case where a redirect is set up on the root path (e.g. redirecting / to some other route).

Thank you!!

madze avatar Sep 16 '22 18:09 madze

Thank you for the feedback @madze , that a good new :)

guillaume-chervet avatar Sep 20 '22 20:09 guillaume-chervet

May we close the issue?

guillaume-chervet avatar Sep 20 '22 20:09 guillaume-chervet

@guillaume-chervet - Yes, absolutely! Sorry, I should have added that in the last message.

madze avatar Sep 29 '22 17:09 madze

Thank you very much @madze

guillaume-chervet avatar Sep 29 '22 18:09 guillaume-chervet