Skip to content

Commit

Permalink
removes duplicated code in getcookieheader
Browse files Browse the repository at this point in the history
Co-authored-by: Austin Feight <[email protected]>
  • Loading branch information
AlbertoElias and afeight authored Oct 16, 2024
1 parent 0785dff commit 7a7f647
Showing 1 changed file with 2 additions and 15 deletions.
17 changes: 2 additions & 15 deletions packages/server/src/auth/utils/cookies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,13 @@ function getCookieHeader(request: GenericRequest): string {
let cookieHeader: string;

if (isNodeRequest(request)) {
cookieHeader = getCookieHeaderFromNodeRequest(request);
cookieHeader = request.headers.cookie;
} else if (isFetchRequest(request)) {
cookieHeader = getCookieHeaderFromFetchRequest(request);
cookieHeader = request.headers.get("Cookie");
} else {
throw new CrossmintAuthenticationError("Unsupported request type");
}

return cookieHeader;
}

function getCookieHeaderFromNodeRequest(request: IncomingMessage): string {
const cookieHeader = request.headers.cookie;
if (cookieHeader == null) {
throw new CrossmintAuthenticationError("Cookie header not found");
}
return cookieHeader;
}

function getCookieHeaderFromFetchRequest(request: Request): string {
const cookieHeader = request.headers.get("Cookie");
if (cookieHeader == null) {
throw new CrossmintAuthenticationError("Cookie header not found");
}
Expand Down

0 comments on commit 7a7f647

Please sign in to comment.