Skip to content

Commit

Permalink
Use a non-default ttl with iron-session (#1186)
Browse files Browse the repository at this point in the history
## Description
iron-session has a default ttl of 14 days, which is problematic in the
edge case where a user has set their WorkOS sessions to expire > 14
days. In that scenario, iron-session will expire first, making unsealing
impossible which means you can't refresh the session.

This fix changes the default ttl to 0, which sets it to the max of ~10
years.

## Documentation

Does this require changes to the WorkOS Docs? E.g. the [API
Reference](https://workos.com/docs/reference) or code snippets need
updates.

```
[ ] Yes
```

If yes, link a related docs PR and add a docs maintainer as a reviewer.
Their approval is required.
  • Loading branch information
PaulAsjes authored Dec 12, 2024
1 parent f3eb43c commit 5a03dd1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/common/iron-session/edge-iron-session-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ import {
export class EdgeIronSessionProvider extends IronSessionProvider {
/** @override */
async sealData(data: unknown, options: SealDataOptions): Promise<string> {
return sealData(data, options);
// The iron-session default ttl is 14 days, which can be problematic if the WorkOS session is configured to be > 14 days.
// In that case the session expires and can't be refreshed, so we set the ttl to 0 to set it to the max possible value.
const sealOptions = {
...options,
ttl: 0,
};
return sealData(data, sealOptions);
}

/** @override */
Expand Down
8 changes: 7 additions & 1 deletion src/common/iron-session/web-iron-session-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ import {
export class WebIronSessionProvider extends IronSessionProvider {
/** @override */
async sealData(data: unknown, options: SealDataOptions): Promise<string> {
return sealData(data, options);
// The iron-session default ttl is 14 days, which can be problematic if the WorkOS session is configured to be > 14 days.
// In that case the session expires and can't be refreshed, so we set the ttl to 0 to set it to the max possible value.
const sealOptions = {
...options,
ttl: 0,
};
return sealData(data, sealOptions);
}

/** @override */
Expand Down

0 comments on commit 5a03dd1

Please sign in to comment.