Skip to content

Commit

Permalink
fix: header reading trying to access undefined res (#667)
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiofra98 authored Nov 3, 2023
1 parent cfe4a1a commit 7abfe9b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/hot-stingrays-laugh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@supabase/auth-helpers-nextjs': patch
---

Fix header and cookie trying to read undefined response body
6 changes: 4 additions & 2 deletions packages/nextjs/src/pagesServerClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ class NextServerAuthStorageAdapter extends CookieAuthStorageAdapter {
}

protected getCookie(name: string): string | null | undefined {
const setCookie = splitCookiesString(this.context.res.getHeader('set-cookie')?.toString() ?? '')
const setCookie = splitCookiesString(
this.context.res?.getHeader('set-cookie')?.toString() ?? ''
)
.map((c) => parseCookies(c)[name])
.find((c) => !!c);

const value = setCookie ?? this.context.req.cookies[name];
const value = setCookie ?? this.context.req?.cookies[name];
return value;
}
protected setCookie(name: string, value: string): void {
Expand Down

0 comments on commit 7abfe9b

Please sign in to comment.