Skip to content

Commit

Permalink
📝 Bring 1st part of sessions doc up-to-date
Browse files Browse the repository at this point in the history
  • Loading branch information
acusti committed Nov 15, 2024
1 parent becbbb0 commit e081531
Showing 1 changed file with 17 additions and 31 deletions.
48 changes: 17 additions & 31 deletions packages/superflare/docs/sessions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<Env>(request, env, ctx, config, handleRequest);
} catch (error) {
console.log(error);
return new Response("An unexpected error occurred", { status: 500 });
}
},
} satisfies ExportedHandler<Env>;
```

## Using sessions
Expand Down

0 comments on commit e081531

Please sign in to comment.