From e081531a6ae61e99550e3dc450554d55b65b920a Mon Sep 17 00:00:00 2001 From: Andrew Patton Date: Fri, 15 Nov 2024 15:26:50 -0800 Subject: [PATCH] :memo: Bring 1st part of sessions doc up-to-date --- packages/superflare/docs/sessions.md | 48 ++++++++++------------------ 1 file changed, 17 insertions(+), 31 deletions(-) diff --git a/packages/superflare/docs/sessions.md b/packages/superflare/docs/sessions.md index ce6c28ab..4f995983 100644 --- a/packages/superflare/docs/sessions.md +++ b/packages/superflare/docs/sessions.md @@ -11,41 +11,27 @@ The `SuperflareSession` instance keeps track of any changes to the session, and _The following examples assume you are using Remix. They will be updated when Superflare supports other frameworks._ -To create a `SuperflareSession` instance, pass a valid `Session` instance: +The `@superflare/remix` package exports `handleFetch`, which takes care of session creation and makes the session available on your Remix `AppContext`. In your main worker file, you import and use the utility like so: ```ts // worker.ts -import { SuperflareSession } from "superflare"; - -// Create a Remix `session`... -const session = "..."; - -const superflareSession = new SuperflareSession(session); -``` - -Then, you can inject the session into your Remix `loadContext`: - -```ts -// worker.ts - -const loadContext = { session, env }; - -try { - const config = getConfig({ request, env, ctx }); - - return handleFetch( - { - config, - session, - getSessionCookie: () => - sessionStorage.commitSession(session.getSession()), - }, - () => remixHandler(request, loadContext) - ); -} catch (error) { - return new Response("Internal Server Error", { status: 500 }); -} +import { createRequestHandler, type ServerBuild } from "@remix-run/cloudflare"; +import { handleFetch } from "@superflare/remix"; +import config from "./superflare.config"; + +const handleRequest = createRequestHandler(build as any as ServerBuild); + +export default { + async fetch(request, env, ctx) { + try { + return await handleFetch(request, env, ctx, config, handleRequest); + } catch (error) { + console.log(error); + return new Response("An unexpected error occurred", { status: 500 }); + } + }, +} satisfies ExportedHandler; ``` ## Using sessions