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

feat(next): external storage #896

Merged
merged 1 commit into from
Jan 7, 2025

Conversation

wangsijie
Copy link
Contributor

@wangsijie wangsijie commented Dec 31, 2024

Summary

This PR adds support for custom external session storage. Resolves logto-io/logto#6597.

Add sessionWrapper to the config, you can implement your own session wrapper to support custom external session storage.

Take a look at the example below:

import { MemorySessionWrapper } from './storage';

export const config = {
  // ...
  sessionWrapper: new MemorySessionWrapper(),
};
import { randomUUID } from 'node:crypto';

import { type SessionWrapper, type SessionData } from '@logto/next';

export class MemorySessionWrapper implements SessionWrapper {
  private readonly storage = new Map<string, unknown>();

  async wrap(data: unknown, _key: string): Promise<string> {
    const sessionId = randomUUID();
    this.storage.set(sessionId, data);
    return sessionId;
  }

  async unwrap(value: string, _key: string): Promise<SessionData> {
    if (!value) {
      return {};
    }

    const data = this.storage.get(value);
    return data ?? {};
  }
}

You can implement your own session wrapper to support custom external session storage like Redis, Memcached, etc.

Testing

Tested with sample projects.

Checklist

  • .changeset
  • unit tests
  • integration tests
  • necessary TSDoc comments

@wangsijie wangsijie requested a review from a team December 31, 2024 06:25
@wangsijie wangsijie force-pushed the wangsijie-log-10078-large-session-size branch from 46ef94d to d33636e Compare January 1, 2025 06:49
Base automatically changed from wangsijie-log-10606-react-sdk-with-nextjs to master January 2, 2025 05:32
@wangsijie wangsijie force-pushed the wangsijie-log-10078-large-session-size branch from d33636e to 973e95a Compare January 7, 2025 08:06
@wangsijie wangsijie merged commit a0f91a3 into master Jan 7, 2025
20 checks passed
@wangsijie wangsijie deleted the wangsijie-log-10078-large-session-size branch January 7, 2025 11:40
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.

bug: Infinite login loop due to cookie size limit exceeded.
2 participants