Skip to content

Conversation

@wangsijie
Copy link
Contributor

@wangsijie wangsijie commented Dec 31, 2025

Summary

Fix the MemorySessionWrapper example to reuse session IDs instead of generating a new UUID on every wrap() call.

Problem

The previous example generated a new randomUUID() on every wrap() call. This breaks in environments where cookies cannot be updated (e.g., React Server Components), because:

  1. wrap() saves data with a new session ID
  2. setCookie() is skipped (RSC is read-only)
  3. Cookie still contains the old session ID
  4. Next request uses old ID → session data lost

The previous example generated a new UUID on every wrap() call.
This breaks RSC environments where cookies cannot be updated,
causing session loss when the cookie still contains the old ID.

Updated the MemorySessionWrapper example to store and reuse the
session ID from unwrap(), ensuring the cookie value remains stable
while external storage data can be updated.
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Dec 31, 2025

Deploying logto-docs-tutorials with  Cloudflare Pages  Cloudflare Pages

Latest commit: 6d9350c
Status: ✅  Deploy successful!
Preview URL: https://78a8f900.logto-docs-tutorials.pages.dev
Branch Preview URL: https://fix-session-wrapper-reuse-id.logto-docs-tutorials.pages.dev

View logs

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Dec 31, 2025

Deploying logto-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: 6d9350c
Status: ✅  Deploy successful!
Preview URL: https://aff4410a.logto-docs.pages.dev
Branch Preview URL: https://fix-session-wrapper-reuse-id.logto-docs.pages.dev

View logs

Expanded the tip about RSC not being able to persist refreshed tokens.
Added clear solutions: using client components with Server Actions,
or using external session storage with sessionWrapper.
@wangsijie wangsijie merged commit 883866f into master Dec 31, 2025
19 checks passed
@wangsijie wangsijie deleted the fix/session-wrapper-reuse-id branch December 31, 2025 06:56
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.

3 participants