keycloakify / oidc-spa

Openid connect client for Single Page Applications
https://www.oidc-spa.dev
MIT License
48 stars 6 forks source link

Can this library be used with Nextjs 14 app router #26

Closed saujanya01 closed 1 month ago

saujanya01 commented 1 month ago

When trying to implement the way given in example, I am getting a ReferenceError: window not defined. This is because of the server side rendering in nextjs 14 app router. Also, looking into the example and the new open pull request (https://github.com/keycloakify/oidc-spa/pull/25) made me wonder if this can work with the routing used in next js. If there is a way to make it work, what would be the best way, if not what are the alternatives I can use other than keycloak-js

garronej commented 1 month ago

Hello @saujanya01,

The oidc-spa module is designed specifically for OpenID Connect in single-page applications. Next.js, particularly when using the App Router, doesn’t fall into this category because much of its logic is executed on the server.

In the future, I might develop another module, oidc-mpa, tailored for multi-page applications to support Next.js. However, this is not my top priority at the moment, as there is already a decent solution available:

You can use NextAuth.js with the Keycloak adapter.

Best regards,

saujanya01 commented 1 month ago

Thanks for clarification. Closing this issue.