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

One class to let oidc-client-ts support SSR. #1760

Open
jim-king-2000 opened this issue Dec 2, 2024 · 0 comments
Open

One class to let oidc-client-ts support SSR. #1760

jim-king-2000 opened this issue Dec 2, 2024 · 0 comments

Comments

@jim-king-2000
Copy link

jim-king-2000 commented Dec 2, 2024

Add the following class:

import Cookies from "universal-cookie";

export class CookieStorage {
  constructor(cookieHeader) {
    this._cookies = new Cookies(cookieHeader);
  }
  getItem(key) {
    return this._cookies.get(encodeURIComponent(key), { doNotParse: true });
  }

  setItem(key, value) {
    return this._cookies.set(encodeURIComponent(key), value, { maxAge: 1000 });
  }

  removeItem(key) {
    return this._cookies.remove(encodeURIComponent(key));
  }
}

And config it:

export function config(cookieHeaders)
{
    const cookieStorage = new CookieStorage(cookieHeaders);
    return {
        userStore: new WebStorageStateStore({ store: cookieStorage }),
        stateStore: new WebStorageStateStore({ store: cookieStorage }),
    };
}

Then, oidc-client-ts can work on the server side. Enjoy.

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

1 participant