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

Allow for configurable Session Storage #40

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

nicknisi
Copy link
Contributor

@nicknisi nicknisi commented Feb 2, 2025

Replace Cookie Singleton with SessionStorageManager

Overview

This PR replaces our current cookie singleton approach with a more flexible and testable SessionStorageManager class. The key changes:

  1. Remove cookie.ts in favor of a new sessionStorage.ts module
  2. Introduce SessionStorageManager class to handle session storage configuration
  3. Support custom session storage/cookie configurations
  4. Improve handling of concurrent session configuration in Remix's parallel loader environment

Key Changes

  • Removed direct cookie singleton export in favor of configureSessionStorage and getSessionStorage functions
  • Added SessionStorageManager class with proper promise-based configuration handling
  • Extended AuthKitLoaderOptions to support custom storage and cookie configurations
  • Improved race condition handling for parallel loader execution
  • Updated tests to match new architecture

Example Usage

// in root.tsx
const cookie = createCookie("_session", {
  path: "/",
  httpOnly: true,
  secure: isSecureProtocol,
  sameSite: "lax",
  maxAge: 60 * 60 * 24 * 400,
  secrets: [
    process.env.WORKOS_COOKIE_PASSWORD
  ],
});

export const loader = (args: LoaderFunctionArgs) =>
  authkitLoader(
    args,
    async () => {
      return json({
        signInUrl: await getSignInUrl(),
      });
    },
    {
      debug: true,
      cookie,
      storage: createMemorySessionStorage({
        cookie,
      }),
    }
  );

Fixes #2

@nicknisi nicknisi force-pushed the nicknisi/session-storage branch from 2e57c56 to 88d3e71 Compare February 2, 2025 22:40
@nicknisi nicknisi force-pushed the nicknisi/session-storage branch from f9f8255 to 0196de1 Compare February 3, 2025 03:00
@nicknisi nicknisi marked this pull request as ready for review February 3, 2025 03:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Custom Session Storage implementation and data
1 participant