From 8b520217c3418f96487710a4ef0487bf5c363099 Mon Sep 17 00:00:00 2001 From: Daniel Reichhart <34721312+reichhartd@users.noreply.github.com> Date: Thu, 30 May 2024 19:28:04 +0200 Subject: [PATCH] Allow logout function to receive a HeadersInit (#271) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: headers for logout * Apply suggestions from code review --------- Co-authored-by: Sergio Xalambrí --- src/authenticator.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/authenticator.ts b/src/authenticator.ts index 888a8c9..c18c92e 100644 --- a/src/authenticator.ts +++ b/src/authenticator.ts @@ -267,16 +267,18 @@ export class Authenticator { */ async logout( request: Request | Session, - options: { redirectTo: string } + options: { redirectTo: string; headers?: HeadersInit } ): Promise { let session = isSession(request) ? request : await this.sessionStorage.getSession(request.headers.get("Cookie")); - throw redirect(options.redirectTo, { - headers: { - "Set-Cookie": await this.sessionStorage.destroySession(session), - }, - }); + let headers = new Headers(options.headers); + headers.append( + "Set-Cookie", + await this.sessionStorage.destroySession(session) + ); + + throw redirect(options.redirectTo, { headers }); } }