Skip to content

Commit

Permalink
Pass client secret to cookie adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
dovca committed Oct 16, 2024
1 parent fbfed30 commit 9c05876
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/session-adapters/createCookieAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@ import jwt from 'jsonwebtoken'
import { Adapter } from './publicAdapter'
import { isAppSession } from '../session'

const clientSecret = process.env['CLIENT_SECRET'] || ''
const defaultSessionKey = 'sb.auth'
const defaultClientSecret = process.env['CLIENT_SECRET'] || ''

type CreateCookieAdapter = (params?: {
sessionKey?: string | undefined
clientSecret?: string | undefined
}) => Adapter

export const createCookieAdapter: CreateCookieAdapter = (params) => {
const key = params?.sessionKey ?? defaultSessionKey
const clientSecret = params?.clientSecret ?? defaultClientSecret

const adapter: Adapter = {
getSession: ({ req, spaceId, userId }) => {
Expand Down
5 changes: 4 additions & 1 deletion src/session/sessionStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ export const getSessionStore: AppSessionCookieStoreFactory =
params,
req: requestParams.req,
res: requestParams.res,
adapter: createCookieAdapter({ sessionKey: params.sessionKey }),
adapter: createCookieAdapter({
sessionKey: params.sessionKey,
clientSecret: params.clientSecret,
}),
})

return {
Expand Down
5 changes: 4 additions & 1 deletion src/storyblok-auth-api/auth-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ export const authHandler = (
params,
req,
res,
adapter: createCookieAdapter({ sessionKey: params.sessionKey }),
adapter: createCookieAdapter({
sessionKey: params.sessionKey,
clientSecret: params.clientSecret,
}),
})

const responseElement = await handleAnyRequest({
Expand Down

0 comments on commit 9c05876

Please sign in to comment.