Skip to content

Commit

Permalink
Merge pull request #221 from jimohalloran/invalid_locale
Browse files Browse the repository at this point in the history
Ensure cookie contains known locale
  • Loading branch information
cretueusebiu authored Oct 31, 2020
2 parents abe4b8a + 58140fc commit 762680b
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion resources/js/store/modules/lang.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,19 @@ import * as types from '../mutation-types'

const { locale, locales } = window.config

function validateCookieLocale () {
const cookieLocale = Cookies.get('locale') || locale
if (locales.hasOwnProperty(cookieLocale)) {
return cookieLocale
} else {
Cookies.set('locale', locale, { expires: 365 })
return locale
}
}

// state
export const state = {
locale: Cookies.get('locale') || locale,
locale: validateCookieLocale(),
locales: locales
}

Expand Down

0 comments on commit 762680b

Please sign in to comment.