Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cookie): Use the shop cookie name for default route #2839

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions packages/core/src/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.`,
Expand Down Expand Up @@ -410,19 +410,21 @@ export function configureSessionCookies(
userConfig: Readonly<RuntimeVendureConfig>,
): 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,
}),
);
}
}
Loading