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

feat(core): configurable cookie attributes #6715

Merged
merged 5 commits into from
May 6, 2022
Merged
Show file tree
Hide file tree
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
8 changes: 8 additions & 0 deletions packages/core/docs/changelog/6715.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
description: 'Add option to configure locale, currency and country cookie attributes for the i18nCookiesPlugin',
link: 'https://github.com/vuestorefront/vue-storefront/pull/6715',
isBreaking: false,
breakingChanges: [],
author: 'Marcin Sulowski',
linkToGitHubAccount: 'https://github.com/MarcinSulowski'
};
18 changes: 18 additions & 0 deletions packages/core/docs/getting-started/internationalization.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,21 @@ modules: [
},
}
```
## Configuring cookie attributes

You can overwrite the default `currency`, `locale`, and `country` cookie attributes set by the `@vue-storefront/nuxt` module or add new ones. Create a new `cookieOptions` object for the `i18n` configuration object in the `nuxt.config.js` file and specify the attributes you'd like the cookies to have.

```js
// nuxt.config.js

export default {
i18n: {
cookieOptions: {
// default attributes used by the `@vue-storefront/nuxt` module
path: '/',
sameSite: 'lax',
expires: new Date(new Date().setFullYear(new Date().getFullYear() + 1))
}
}
}
```
3 changes: 2 additions & 1 deletion packages/core/nuxt-module/plugins/i18n-cookies.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ const i18nCookiesPlugin = ({ $cookies, i18n, app, redirect }) => {
const cookieOptions = {
path: '/',
sameSite: 'lax',
expires: new Date(new Date().setFullYear(new Date().getFullYear() + 1)) // Year from now
expires: new Date(new Date().setFullYear(new Date().getFullYear() + 1)), // Year from now
...i18nOptions.cookieOptions
};
const settings = {
locale: targetLocale,
Expand Down