Skip to content

Commit

Permalink
Merge branch 'main' into tobbe-chore-nx-2030
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobbe authored Dec 29, 2024
2 parents b895253 + faf752e commit 435b8e3
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions packages/api/src/auth/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export * from './parseJWT'

import type { APIGatewayProxyEvent, Context as LambdaContext } from 'aws-lambda'
import { parse as parseCookie } from 'cookie'
import * as cookie from 'cookie'

import { getEventHeader } from '../event'

Expand Down Expand Up @@ -29,26 +29,26 @@ export interface AuthorizationHeader {
}

export type AuthorizationCookies = {
parsedCookie: Record<string, string>
parsedCookie: Record<string, string | undefined>
rawCookie: string
type: string
type: string | undefined
} | null

export const parseAuthorizationCookie = (
event: APIGatewayProxyEvent | Request,
): AuthorizationCookies => {
const cookie = getEventHeader(event, 'Cookie')
const cookieHeader = getEventHeader(event, 'Cookie')

// Unauthenticated request
if (!cookie) {
if (!cookieHeader) {
return null
}

const parsedCookie = parseCookie(cookie)
const parsedCookie = cookie.parse(cookieHeader)

return {
parsedCookie,
rawCookie: cookie,
rawCookie: cookieHeader,
// When not unauthenticated, this will be null/undefined
// Remember that the cookie header could contain other (unrelated) values!
type: parsedCookie[AUTH_PROVIDER_HEADER],
Expand Down

0 comments on commit 435b8e3

Please sign in to comment.