Skip to content

Commit

Permalink
fix: update cookie values on request object. (#42)
Browse files Browse the repository at this point in the history
* fix: update cookie values on request object.

* chore: update changelog.
  • Loading branch information
thorwebdev authored Mar 16, 2022
1 parent 80173be commit e188cb9
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
4 changes: 4 additions & 0 deletions src/shared/adapters/NextAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down
1 change: 1 addition & 0 deletions src/shared/adapters/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions src/shared/utils/cookies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ export function setCookies(
res: ResponseAdapter,
cookies: Array<Cookie>
) {
for (let cookie of cookies) {
req.setRequestCookie(cookie.name, cookie.value);
}
res.setHeader('Set-Cookie', getCookieString(req, res, cookies));
}

Expand Down

0 comments on commit e188cb9

Please sign in to comment.