feat(medusa): Expose session options (#3162)
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@medusajs/medusa": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
feat(medusa): Expose session options
|
||||||
@@ -4,16 +4,16 @@ import {
|
|||||||
AwilixContainer,
|
AwilixContainer,
|
||||||
ClassOrFunctionReturning,
|
ClassOrFunctionReturning,
|
||||||
createContainer,
|
createContainer,
|
||||||
Resolver,
|
Resolver
|
||||||
} from "awilix"
|
} from "awilix"
|
||||||
import Logger from "../logger"
|
|
||||||
import {
|
import {
|
||||||
ConfigModule,
|
ConfigModule,
|
||||||
MedusaContainer,
|
MedusaContainer,
|
||||||
ModuleResolution,
|
ModuleResolution,
|
||||||
MODULE_RESOURCE_TYPE,
|
MODULE_RESOURCE_TYPE,
|
||||||
MODULE_SCOPE,
|
MODULE_SCOPE
|
||||||
} from "../../types/global"
|
} from "../../types/global"
|
||||||
|
import Logger from "../logger"
|
||||||
import registerModules from "../module"
|
import registerModules from "../module"
|
||||||
import { trackInstallation } from "../__mocks__/medusa-telemetry"
|
import { trackInstallation } from "../__mocks__/medusa-telemetry"
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
|
import createStore from "connect-redis"
|
||||||
|
import cookieParser from "cookie-parser"
|
||||||
import { Express } from "express"
|
import { Express } from "express"
|
||||||
import session from "express-session"
|
import session from "express-session"
|
||||||
import cookieParser from "cookie-parser"
|
|
||||||
import morgan from "morgan"
|
import morgan from "morgan"
|
||||||
import redis, { RedisConfig } from "redis"
|
import redis from "redis"
|
||||||
import createStore from "connect-redis"
|
|
||||||
import { ConfigModule } from "../types/global"
|
import { ConfigModule } from "../types/global"
|
||||||
|
|
||||||
type Options = {
|
type Options = {
|
||||||
@@ -22,17 +22,17 @@ export default async ({ app, configModule }: Options): Promise<Express> => {
|
|||||||
sameSite = "none"
|
sameSite = "none"
|
||||||
}
|
}
|
||||||
|
|
||||||
const { cookie_secret } = configModule.projectConfig
|
const { cookie_secret, session_options } = configModule.projectConfig
|
||||||
const sessionOpts = {
|
const sessionOpts = {
|
||||||
resave: true,
|
resave: session_options?.resave ?? true,
|
||||||
saveUninitialized: true,
|
saveUninitialized: session_options?.saveUninitialized ?? true,
|
||||||
cookieName: "session",
|
cookieName: "session",
|
||||||
proxy: true,
|
proxy: true,
|
||||||
secret: cookie_secret,
|
secret: session_options?.secret ?? cookie_secret,
|
||||||
cookie: {
|
cookie: {
|
||||||
sameSite,
|
sameSite,
|
||||||
secure,
|
secure,
|
||||||
maxAge: 10 * 60 * 60 * 1000,
|
maxAge: session_options?.ttl ?? 10 * 60 * 60 * 1000,
|
||||||
},
|
},
|
||||||
store: null,
|
store: null,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -100,10 +100,19 @@ export type ModuleExports = {
|
|||||||
models?: Constructor<any>[]
|
models?: Constructor<any>[]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type SessionOptions = {
|
||||||
|
resave?: boolean
|
||||||
|
saveUninitialized?: boolean
|
||||||
|
secret?: string
|
||||||
|
ttl?: number
|
||||||
|
}
|
||||||
|
|
||||||
export type ConfigModule = {
|
export type ConfigModule = {
|
||||||
projectConfig: {
|
projectConfig: {
|
||||||
redis_url?: string
|
redis_url?: string
|
||||||
|
|
||||||
|
session_options?: SessionOptions
|
||||||
|
|
||||||
jwt_secret?: string
|
jwt_secret?: string
|
||||||
cookie_secret?: string
|
cookie_secret?: string
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user