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

Nextjs support #850

Open
geniusit opened this issue Sep 7, 2022 · 19 comments
Open

Nextjs support #850

geniusit opened this issue Sep 7, 2022 · 19 comments

Comments

@geniusit
Copy link

geniusit commented Sep 7, 2022

I try to use the library in a nextjs application.
I just replace default value with these :

image

I got this error when accessing localhost:3001 :

image

I also see that the query params are not sent.

image

Did I misunderstand something with the library?
Is this library able to work in a context outside of axa?

@guillaume-chervet
Copy link
Contributor

Hi @geniusit ,

Thank you for your issue. The library should work with any oidc provider.

Which oidc provider do you use?

What append if you update scope to :

scope: "openid profile offline_access",

@geniusit
Copy link
Author

geniusit commented Sep 7, 2022

@guillaume-chervet
I use OpenAM
I tried to change the scope with "openid profile offline_access" but the issue still persists.

@guillaume-chervet
Copy link
Contributor

Thank you, i will make a test with openam.

@guillaume-chervet
Copy link
Contributor

I did not get the time to test today. I will try tomorrow @geniusit , Thank you it will help to make the library better.

@geniusit
Copy link
Author

geniusit commented Sep 7, 2022

@guillaume-chervet No problem. Thank you too. BTW we are former colleagues ;) I ve worked for AXA too (Wasquehal)

@guillaume-chervet
Copy link
Contributor

I am sorry for the delay @geniusit . I am on it as soon as i can. I have a bush month ^^

@fffan64
Copy link

fffan64 commented Oct 18, 2022

next.js is not made for spa, so i doubt you can use this lib.

maybe it will be possible with that: https://nextjs.org/blog/layouts-rfc but not available yet

@guillaume-chervet
Copy link
Contributor

Hi @fffan64 , react oidc is compatible with nextjs. But Server side rendering won't work well on the not authorised part. I have to check why it does work with OpenAM. Very sorry @geniusit for the delay.

@ZeKap
Copy link

ZeKap commented May 22, 2023

Hello, I've tried using react-oidc on NextJS 13 using the /app route instead of /pages, but looking at the example for NextJS it seems like it's not actually possible since we're using 'next/router' which isn't compatible with the /app router. I'm not sure to understand everything in the example, but I've tried my best, maybe you have an idea to do a workaround?

Also, with what I tried I have the error:
Error authentication An error occurred during authentication.
right after the login('/account') but looking at the console I don't have much more informations. The login seems to work sometimes because I get a token and its countdown, but still get the error page.

@vanquishkuso
Copy link

vanquishkuso commented May 31, 2023

@ZeKap Hi, I got it to work with /app folder in Next.js 13.4.0. I just changed it to windows.location.href, maybe not the most optimal solution but it works until router gets another workaround/fix.

const withCustomHistory = () => { return { replaceState: (url: string) => (window.location.href = url), }; };

@guillaume-chervet
Copy link
Contributor

guillaume-chervet commented Aug 8, 2023

hi @vanquishkuso , I Close the issue. It is compatible nextjs and more now.
Thank you very much for your issue.

@vanquishkuso
Copy link

Hi @guillaume-chervet, great to hear. Although it might be off topic, I also had problem with oidc-react preventing the server from initially loading the page (it instead showing a white loading page). I assume this is bad for SEO. Can this be fixed or overwritten in some way?

@guillaume-chervet
Copy link
Contributor

Hi @vanquishkuso , yes I will solve this issue. Thank your for your feedback. I reopen the issue to trace it.

@vanquishkuso
Copy link

That's great to hear! I have tried to get other packages to work with SSR but I just can't get it to work. Will your fix also work for child components calling useOidc() even though the package hasn't authenticated them (e.g. window hasn't been loaded in the provider or before dynamic urls has been set in the oidc config)?

@guillaume-chervet
Copy link
Contributor

hi @vanquishkuso , I have published a first alpha 7.4.0-alpha.1025
where i remove loader.
It works but I think I have to add loader information into hook to make consumer to choose to disploay loader or not.

I'am off during 3 weeks.

@vanquishkuso
Copy link

Hi @guillaume-chervet, great, that was fast! Will give it a test next week.

@vanquishkuso
Copy link

Hi again @guillaume-chervet, I tested to convert our app to oidc-react and I ran in to the same issue as before with router.replace:
Argument of type '{ pathname: any; }' is not assignable to parameter of type 'string'. Property 'then' does not exist on type 'void'.ts(2339)

Adding back the workaround which is not optimal (below), I get it to work, but i get window is not defined.
const withCustomHistory = () => { return { replaceState: (url: string) => (window.location.href = url), }; };

@guillaume-chervet
Copy link
Contributor

Thank you @vanquishkuso for the feedback.
Do you have a sample that can help me to reproduce?
I am off for 3 weeks. I will look at this when i will be back.

@vanquishkuso
Copy link

Hi @guillaume-chervet, I tried to reproduce it in codesandbox but couldn't. It may be something with my setup in my original project.

What I do have problem with is making it work with dynamic configuration. For us, the urls are stored in a json file locally which has to be fetched. When fetch is complete it updates the configuration state. Rendering null if configuration is not set works fine, but then the whole app gets delayed. Is there a workaround for this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants