Skip to content

Commit

Permalink
Remove max-age option from cookieOptions (#637)
Browse files Browse the repository at this point in the history
  • Loading branch information
silentworks authored Sep 16, 2023
1 parent a628d9a commit c48bb87
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 8 deletions.
6 changes: 6 additions & 0 deletions .changeset/few-carrots-mate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@supabase/auth-helpers-nextjs': minor
'@supabase/auth-helpers-shared': minor
---

Remove max-age option from cookieOptions
3 changes: 2 additions & 1 deletion packages/nextjs/src/middlewareClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
CookieOptions,
CookieOptionsWithName,
createSupabaseClient,
DefaultCookieOptions,
parseCookies,
serializeCookie,
SupabaseClientOptionsWithoutAuth
Expand Down Expand Up @@ -45,7 +46,7 @@ class NextMiddlewareAuthStorageAdapter extends CookieAuthStorageAdapter {
});
}

private _setCookie(name: string, value: string, options?: CookieOptions) {
private _setCookie(name: string, value: string, options?: DefaultCookieOptions) {
const newSessionStr = serializeCookie(name, value, {
...this.cookieOptions,
...options,
Expand Down
3 changes: 2 additions & 1 deletion packages/nextjs/src/pagesServerClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
CookieOptions,
CookieOptionsWithName,
createSupabaseClient,
DefaultCookieOptions,
parseCookies,
serializeCookie,
SupabaseClientOptionsWithoutAuth
Expand Down Expand Up @@ -40,7 +41,7 @@ class NextServerAuthStorageAdapter extends CookieAuthStorageAdapter {
});
}

private _setCookie(name: string, value: string, options?: CookieOptions) {
private _setCookie(name: string, value: string, options?: DefaultCookieOptions) {
const setCookies = splitCookiesString(
this.context.res.getHeader('set-cookie')?.toString() ?? ''
).filter((c) => !(name in parseCookies(c)));
Expand Down
7 changes: 4 additions & 3 deletions packages/shared/src/cookieAuthStorageAdapter.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import { GoTrueClientOptions, Session } from '@supabase/supabase-js';
import { DEFAULT_COOKIE_OPTIONS, parseSupabaseCookie, stringifySupabaseSession } from './utils';
import { CookieOptions } from './types';
import { CookieOptions, DefaultCookieOptions } from './types';

export interface StorageAdapter extends Exclude<GoTrueClientOptions['storage'], undefined> {}

export abstract class CookieAuthStorageAdapter implements StorageAdapter {
protected readonly cookieOptions: CookieOptions;
protected readonly cookieOptions: DefaultCookieOptions;

constructor(cookieOptions?: CookieOptions) {
this.cookieOptions = {
...DEFAULT_COOKIE_OPTIONS,
...cookieOptions
...cookieOptions,
maxAge: DEFAULT_COOKIE_OPTIONS.maxAge
};
}

Expand Down
4 changes: 3 additions & 1 deletion packages/shared/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import type { CookieSerializeOptions } from 'cookie';
import type { SupabaseClientOptions } from '@supabase/supabase-js';

export type CookieOptions = Pick<
export type CookieOptions = Pick<CookieSerializeOptions, 'domain' | 'secure' | 'path' | 'sameSite'>;

export type DefaultCookieOptions = Pick<
CookieSerializeOptions,
'domain' | 'secure' | 'path' | 'sameSite' | 'maxAge'
>;
Expand Down
4 changes: 2 additions & 2 deletions packages/shared/src/utils/constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CookieOptions } from '../types';
import { DefaultCookieOptions } from '../types';

export const DEFAULT_COOKIE_OPTIONS: CookieOptions = {
export const DEFAULT_COOKIE_OPTIONS: DefaultCookieOptions = {
path: '/',
maxAge: 60 * 60 * 24 * 365 * 1000
};

0 comments on commit c48bb87

Please sign in to comment.