mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
Merge pull request #4882 from Ocelot-Social-Community/4342-fix-language-select
fix: 🍰 Add Expiration Date To Cookies Etc.
This commit is contained in:
commit
d9f33ded17
@ -201,6 +201,7 @@ export default {
|
||||
/** * A Boolean indicating if the cookie transmission requires a
|
||||
* secure protocol (https). Defaults to false. */
|
||||
secure: CONFIG.COOKIE_HTTPS_ONLY,
|
||||
sameSite: 'lax', // for the meaning see https://www.thinktecture.com/de/identity/samesite/samesite-in-a-nutshell/
|
||||
},
|
||||
// includeNodeModules: true, // optional, default: false (this includes graphql-tag for node_modules folder)
|
||||
|
||||
|
||||
@ -21,18 +21,30 @@ export default ({ app, req, cookie, store }) => {
|
||||
const changeHandler = async (mutation) => {
|
||||
if (process.server) return
|
||||
|
||||
const newLocale = mutation.payload.locale
|
||||
const currentLocale = await app.$cookies.get(key)
|
||||
const isDifferent = newLocale !== currentLocale
|
||||
const localeInStore = mutation.payload.locale
|
||||
let cookieExists = true
|
||||
let localeInCookies = await app.$cookies.get(key)
|
||||
if (!localeInCookies) {
|
||||
cookieExists = false
|
||||
localeInCookies = navigator.language.split('-')[0] // get browser language
|
||||
}
|
||||
const isLocaleStoreSameAsCookies = localeInStore === localeInCookies
|
||||
|
||||
if (!isDifferent) {
|
||||
// cookie has to be set, otherwise Cypress test does not work
|
||||
if (cookieExists && isLocaleStoreSameAsCookies) {
|
||||
return
|
||||
}
|
||||
|
||||
app.$cookies.set(key, newLocale)
|
||||
if (!app.$i18n.localeExists(newLocale)) {
|
||||
import(`~/locales/${newLocale}.json`).then((res) => {
|
||||
app.$i18n.add(newLocale, res.default)
|
||||
const expires = new Date()
|
||||
expires.setDate(expires.getDate() + app.$env.COOKIE_EXPIRE_TIME)
|
||||
app.$cookies.set(key, localeInStore, {
|
||||
expires,
|
||||
// maxAge: app.$env.COOKIE_EXPIRE_TIME * 60 * 60 * 24, // days to seconds
|
||||
sameSite: 'lax', // for the meaning see https://www.thinktecture.com/de/identity/samesite/samesite-in-a-nutshell/
|
||||
})
|
||||
if (!app.$i18n.localeExists(localeInStore)) {
|
||||
import(`~/locales/${localeInStore}.json`).then((res) => {
|
||||
app.$i18n.add(localeInStore, res.default)
|
||||
})
|
||||
}
|
||||
|
||||
@ -42,7 +54,7 @@ export default ({ app, req, cookie, store }) => {
|
||||
if (user && user._id && token) {
|
||||
// TODO: SAVE LOCALE
|
||||
// store.dispatch('usersettings/patch', {
|
||||
// uiLanguage: newLocale
|
||||
// uiLanguage: localeInStore
|
||||
// }, { root: true })
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user