From 0a657e014322de281f39e736bf285672b5705914 Mon Sep 17 00:00:00 2001 From: "alexis.vigoureux" Date: Tue, 7 May 2024 10:44:00 +0200 Subject: [PATCH] fix-cookie-name-on-rest-route --- packages/core/src/bootstrap.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/packages/core/src/bootstrap.ts b/packages/core/src/bootstrap.ts index f890a0eaf4..a18c89d7f5 100644 --- a/packages/core/src/bootstrap.ts +++ b/packages/core/src/bootstrap.ts @@ -250,7 +250,7 @@ function checkPluginCompatibility(config: RuntimeVendureConfig): void { if (!satisfies(VENDURE_VERSION, compatibility, { loose: true, includePrerelease: true })) { Logger.error( `Plugin "${pluginName}" is not compatible with this version of Vendure. ` + - `It specifies a semver range of "${compatibility}" but the current version is "${VENDURE_VERSION}".`, + `It specifies a semver range of "${compatibility}" but the current version is "${VENDURE_VERSION}".`, ); throw new InternalServerError( `Plugin "${pluginName}" is not compatible with this version of Vendure.`, @@ -410,19 +410,21 @@ export function configureSessionCookies( userConfig: Readonly, ): void { const { cookieOptions } = userConfig.authOptions; - app.use( - cookieSession({ - ...cookieOptions, - name: typeof cookieOptions?.name === 'string' ? cookieOptions.name : DEFAULT_COOKIE_NAME, - }), - ); // If the Admin API and Shop API should have specific cookies names if (typeof cookieOptions?.name === 'object') { const shopApiCookieName = cookieOptions.name.shop; const adminApiCookieName = cookieOptions.name.admin; const { shopApiPath, adminApiPath } = userConfig.apiOptions; + app.use(cookieSession({...cookieOptions, name: shopApiCookieName})); app.use(`/${shopApiPath}`, cookieSession({ ...cookieOptions, name: shopApiCookieName })); app.use(`/${adminApiPath}`, cookieSession({ ...cookieOptions, name: adminApiCookieName })); + } else { + app.use( + cookieSession({ + ...cookieOptions, + name: cookieOptions?.name ?? DEFAULT_COOKIE_NAME, + }), + ); } }