Skip to content

Commit

Permalink
chore(dbAuth): Early return to make code easier to read (#11722)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobbe authored Nov 17, 2024
1 parent eb1fb2b commit 3ed44ec
Showing 1 changed file with 26 additions and 25 deletions.
51 changes: 26 additions & 25 deletions packages/auth-providers/dbAuth/api/src/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,34 +40,34 @@ const getPort = () => {
// When in development environment, check for auth impersonation cookie
// if user has generated graphiql headers
const eventGraphiQLHeadersCookie = (event: APIGatewayProxyEvent | Request) => {
if (process.env.NODE_ENV === 'development') {
const impersationationHeader = getEventHeader(
event,
'rw-studio-impersonation-cookie',
)

if (impersationationHeader) {
return impersationationHeader
}
if (process.env.NODE_ENV !== 'development') {
return
}

// TODO: Remove code below when we remove the old way of passing the cookie
// from Studio, and decide it's OK to break compatibility with older Studio
// versions
try {
if (!isFetchApiRequest(event)) {
const jsonBody = JSON.parse(event.body ?? '{}')
return (
jsonBody?.extensions?.headers?.cookie ||
jsonBody?.extensions?.headers?.Cookie
)
}
} catch {
// sometimes the event body isn't json
return
}
const impersationationHeader = getEventHeader(
event,
'rw-studio-impersonation-cookie',
)

if (impersationationHeader) {
return impersationationHeader
}

return
// TODO: Remove code below when we remove the old way of passing the cookie
// from Studio, and decide it's OK to break compatibility with older Studio
// versions
try {
if (!isFetchApiRequest(event)) {
const jsonBody = JSON.parse(event.body ?? '{}')
return (
jsonBody?.extensions?.headers?.cookie ||
jsonBody?.extensions?.headers?.Cookie
)
}
} catch {
// sometimes the event body isn't json
return
}
}

// decrypts session text using old CryptoJS algorithm (using node:crypto library)
Expand Down Expand Up @@ -97,6 +97,7 @@ const legacyDecryptSession = (encryptedText: string) => {
export const extractCookie = (event: APIGatewayProxyEvent | Request) => {
return eventGraphiQLHeadersCookie(event) || getEventHeader(event, 'Cookie')
}

// whether this encrypted session was made with the old CryptoJS algorithm
export const isLegacySession = (text: string | undefined) => {
if (!text) {
Expand Down

0 comments on commit 3ed44ec

Please sign in to comment.