Skip to content

Commit

Permalink
Allow logout function to receive a HeadersInit (#271)
Browse files Browse the repository at this point in the history
* feat: headers for logout

* Apply suggestions from code review

---------

Co-authored-by: Sergio Xalambrí <hello@sergiodxa.com>
  • Loading branch information
reichhartd and sergiodxa committed May 30, 2024
1 parent b22ea79 commit 8b52021
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/authenticator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,16 +267,18 @@ export class Authenticator<User = unknown> {
*/
async logout(
request: Request | Session,
options: { redirectTo: string }
options: { redirectTo: string; headers?: HeadersInit }
): Promise<never> {
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 });
}
}

0 comments on commit 8b52021

Please sign in to comment.