diff --git a/CHANGELOG.md b/CHANGELOG.md index c766203d..b059616a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # CHANGELOG +## 1.2.3 - 2022-03-16 + +- [#42](https://github.com/supabase-community/supabase-auth-helpers/pull/42): fix: update cookie values on request object. + ## 1.2.2 - 2022-03-09 - [#34](https://github.com/supabase-community/supabase-auth-helpers/pull/34): fix: update cookie lifetime default from 8h to 7 days. diff --git a/src/shared/adapters/NextAdapter.ts b/src/shared/adapters/NextAdapter.ts index f13cadf7..eb30e6a0 100644 --- a/src/shared/adapters/NextAdapter.ts +++ b/src/shared/adapters/NextAdapter.ts @@ -15,6 +15,10 @@ export class NextRequestAdapter implements RequestAdapter { this.req = request; } + setRequestCookie(name: string, value: string) { + this.req.cookies[name] = value; + } + getHeader(name: string) { return this.req.headers[name]; } diff --git a/src/shared/adapters/types.ts b/src/shared/adapters/types.ts index 84aa8b29..7ed9a6db 100644 --- a/src/shared/adapters/types.ts +++ b/src/shared/adapters/types.ts @@ -2,6 +2,7 @@ type HeaderTypes = number | string | string[] | undefined | null; export interface RequestAdapter { getHeader(name: string): HeaderTypes; + setRequestCookie(name: string, value: string): void; } export interface ResponseAdapter { diff --git a/src/shared/utils/cookies.ts b/src/shared/utils/cookies.ts index e93a7df5..e10167a0 100644 --- a/src/shared/utils/cookies.ts +++ b/src/shared/utils/cookies.ts @@ -178,6 +178,9 @@ export function setCookies( res: ResponseAdapter, cookies: Array ) { + for (let cookie of cookies) { + req.setRequestCookie(cookie.name, cookie.value); + } res.setHeader('Set-Cookie', getCookieString(req, res, cookies)); }