You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
allow configuring session storage on callback route (#22)
This PR addresses issue #63 where users deploying to serverless
environments (like AWS Lambda) experience errors in the callback route
during cold starts. The error occurs because the session storage
configuration happens in the root loader, but during cold starts the
callback route might be hit first, resulting in:
```
Error: SessionStorage was never configured. Did you forget to call
configureSessionStorage in your root loader?
```
## Changes
- Updated the `authLoader` function to accept the same `storage` and
`cookie` configuration options that `authkitLoader` already supports
- Modified `HandleAuthOptions` type to support these new configuration
options
- Changed the implementation to use `configureSessionStorage` directly
in the callback route
## How It Works
When a cold start happens in a serverless environment, the callback
route can now configure session storage itself through the same
interface already available in `authkitLoader`. This allows developers
to provide consistent session storage configuration to both routes,
ensuring the application works correctly regardless of which route is
hit first.
## Usage
For applications deployed to serverless environments, you can now use
this pattern:
```typescript
// Create a shared configuration function
function getAuthStorage() {
return {
storage: createCookieSessionStorage({...}),
cookie: { name: "my-session" }
};
}
// In your root loader
export const loader = (args) => authkitLoader(args, {
...getAuthStorage(),
// Other options...
});
// In your callback route
export const loader = authLoader({
...getAuthStorage(),
// Other options...
});
```
This ensures consistent session configuration across routes and prevents
cold start errors.
## README changes
This PR also adds a section describing sessoion storage configuration to
the README, and notes the important case to configure in both laoders
(when custom session storage is used).
Fixes #63.
>When deploying to serverless environments like AWS Lambda, ensure you pass the same storage configuration to both your main routes and the callback route to handle cold starts properly.
353
+
354
+
AuthKit works with any session storage that implements React Router's `SessionStorage` interface, including Redis-based or database-backed implementations.
0 commit comments