Sander Bouwmeester
Sander Bouwmeester

Reputation: 85

Cookiestorage does not work for oidc-client on a SSR React implementation

How can I run a React application with the oidc-client in a SSR environment?

I am working on a React implementation which uses the oidc-client (v 1.7.1). In a non-SSR environment the solution is fine. But one of our requirements is that the solution should run in a SSR environment. To solve this problem I need to change the storage in the setup of the oidc-client.

I have tried the solution to use cookie storage instead of the session or localstorage (check https://github.com/IdentityModel/oidc-client-js/issues/269) but this type of storage does not work (the store is undefined).

const settings = {
  userStore: new WebStorageStateStore({ store: new CookieStorage() }),
  stateStore: new WebStorageStateStore({ store: new CookieStorage() }),
};

this.userManager = new UserManager(settings);

What is the best solution to use the oidc-client in an SSR environment? Is the oidc-client usable in combination with SSR?

Upvotes: 1

Views: 3099

Answers (1)

user12203094
user12203094

Reputation: 11

I've been struggling with this for about a day now. I found that the user cookie that oidc-client-js is trying to set is simply too big. The maximum storage size for cookies is 4096 bytes per domain. The value of the cookie itself is around 3,974 bytes. So with the default key (which is kinda lengthy), the domain, expiration, etc., it goes over the size limit. I had to reduce the scope of the returned payload so that it did not include some user profile information, which if you really need it, you should be able to add it to the access token

Upvotes: 1

Related Questions