Skip to content

Commit

Permalink
Added domain option to session (#4951)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yannick authored Feb 28, 2021
1 parent e898b49 commit 880fd5f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/unlucky-news-warn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystone-next/keystone': minor
---

Added `domain` option to session options for cookies.
3 changes: 3 additions & 0 deletions docs-next/pages/apis/session.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export default config({
maxAge: 60 * 60 * 24,
secure: true,
path: '/',
domain: 'localhost',
}),
{ User: 'name isAdmin' }
),
Expand Down Expand Up @@ -62,6 +63,8 @@ Options
For Firefox, the `https:` requirements are ignored when the `secure` attribute is set by localhost (since Firefox 75).
- `path` (default: `'/'`): A path that must exist in the requested URL, or the browser won't send the cookie header.
The forward slash (`/`) character is interpreted as a directory separator, and subdirectories will be matched as well: for `path: '/docs'`, `/docs`, `/docs/Web/`, and `/docs/Web/HTTP` will all match.
- `domain` (default: current document URL): Host to which the cookie will be sent. See [here](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie#attributes) for more details on the `domain` cookie attribute..
**Note**: Only one domain is allowed. If a domain is specified then subdomains are always included.

### Session stores

Expand Down
9 changes: 9 additions & 0 deletions packages-next/keystone/src/session/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ type StatelessSessionsOptions = {
* @default '/'
*/
path?: string;
/**
* Specifies the domain for the {@link https://tools.ietf.org/html/rfc6265#section-5.2.3|`Domain` `Set-Cookie` attribute}
*
* @default current domain
*/
domain?: string;
};

type FieldSelections = {
Expand Down Expand Up @@ -116,6 +122,7 @@ export function statelessSessions<T>({
path = '/',
secure = process.env.NODE_ENV === 'production',
ironOptions = Iron.defaults,
domain,
}: StatelessSessionsOptions): () => SessionStrategy<T> {
return () => {
if (!secret) {
Expand Down Expand Up @@ -143,6 +150,7 @@ export function statelessSessions<T>({
secure,
path,
sameSite: 'lax',
domain,
})
);
},
Expand All @@ -158,6 +166,7 @@ export function statelessSessions<T>({
secure,
path,
sameSite: 'lax',
domain,
})
);

Expand Down

1 comment on commit 880fd5f

@vercel
Copy link

@vercel vercel bot commented on 880fd5f Feb 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.