diff --git a/middleware/i18n.js b/middleware/i18n.js index aba9c471..fad1f75a 100644 --- a/middleware/i18n.js +++ b/middleware/i18n.js @@ -1,5 +1,6 @@ import acceptLanguage from 'accept-language' -export default function ({ req, app, store }) { + +export default async function ({ req, app, store }) { if (process.server) { const acceptedLanguages = req.headers['accept-language'] const supportedLanguages = ['en', 'it', 'es'] diff --git a/nuxt.config.js b/nuxt.config.js index c33aca2d..81bb3fe2 100644 --- a/nuxt.config.js +++ b/nuxt.config.js @@ -25,7 +25,7 @@ module.exports = { ** Global CSS */ css: [ - 'bootstrap/dist/css/bootstrap.css', + 'bootstrap/dist/css/bootstrap.min.css', 'element-ui/lib/theme-chalk/index.css' ], @@ -68,7 +68,7 @@ module.exports = { logout: false, user: { url: '/auth/user', method: 'get', propertyName: false } }, - tokenRequired: false, + tokenRequired: true, tokenType: 'Bearer' } } diff --git a/package.json b/package.json index 4fbf5879..f76969bc 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,7 @@ ".nuxt/" ], "dependencies": { - "@nuxtjs/auth": "^4.8.3", + "@nuxtjs/auth": "^4.8.4", "@nuxtjs/axios": "^5.6.0", "accept-language": "^3.0.18", "axios": "^0.19.0", @@ -74,16 +74,16 @@ "sharp": "^0.23.0", "sqlite3": "^4.1.0", "url": "^0.11.0", - "v-calendar": "^1.0.0-beta.14", + "v-calendar": "^1.0.0-beta.16", "vue-awesome": "^3.5.3", "vue-clipboard2": "^0.3.1", - "vue-i18n": "^8.14.0", + "vue-i18n": "^8.14.1", "yargs": "^14.0.0" }, "devDependencies": { "@nuxtjs/eslint-config": "^1.1.2", "babel-eslint": "^10.0.3", - "eslint": "^6.3.0", + "eslint": "^6.4.0", "eslint-config-prettier": "^6.3.0", "eslint-config-standard": ">=14.1.0", "eslint-loader": "^3.0.0", @@ -99,6 +99,6 @@ "nodemon": "^1.19.2", "prettier": "^1.17.1", "pug-plain-loader": "^1.0.0", - "webpack-cli": "^3.3.8" + "webpack-cli": "^3.3.9" } } diff --git a/plugins/i18n.js b/plugins/i18n.js index 340d6f96..1fdd8f7b 100644 --- a/plugins/i18n.js +++ b/plugins/i18n.js @@ -6,11 +6,9 @@ import locales from '../locales' Vue.use(VueI18n) export default async ({ app, store }) => { - // Set i18n instance on app - // This way we can use it in middleware and pages asyncData/fetch - const user_locale = await app.$axios.$get('/settings/user_locale') - for (const lang in user_locale) { + // Set i18n instance on app + for (const lang in store.state.user_locale) { if (locales[lang]) { merge(locales[lang], user_locale[lang]) } } diff --git a/server/api/controller/user.js b/server/api/controller/user.js index 292f4623..62db22be 100644 --- a/server/api/controller/user.js +++ b/server/api/controller/user.js @@ -38,7 +38,6 @@ const userController = { }, config.secret ) - res.cookie('auth._token.local', 'Bearer ' + accessToken) res.json({ token: accessToken }) } } diff --git a/store/index.js b/store/index.js index 8c5ce484..4d40ddad 100644 --- a/store/index.js +++ b/store/index.js @@ -4,6 +4,7 @@ import find from 'lodash/find' export const state = () => ({ locale: '', + user_locale: {}, events: [], tags: [], places: [], @@ -137,10 +138,14 @@ export const mutations = { export const actions = { // this method is called server side only for each request // we use it to get configuration from db, setting locale, etc... - async nuxtServerInit ({ commit }, { app, req }) { + async nuxtServerInit ({ commit }, { app, store, req }) { const settings = await app.$axios.$get('/settings') commit('setSettings', settings) + // check if we could retrieve it directly? + const user_locale = await app.$axios.$get('/settings/user_locale') + if (user_locale[store.state.locale]) { store.commit('setUserLocale', user_locale[store.state.locale]) } + // apply settings commit('showRecurrentEvents', settings.allow_recurrent_event && settings.recurrent_event_visible) }, diff --git a/yarn.lock b/yarn.lock index 370d3c3e..dce2ec45 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1005,10 +1005,10 @@ webpack-node-externals "^1.7.2" webpackbar "^4.0.0" -"@nuxtjs/auth@^4.8.3": - version "4.8.3" - resolved "https://registry.yarnpkg.com/@nuxtjs/auth/-/auth-4.8.3.tgz#037509e0dea0329c9dae7be4f743cd9ff701efa5" - integrity sha512-t9RsEH/IdEl+tzR3qOV6lQlXv0sqD4CTdtJnpseVL7lBn1f1cKGGyDXsWdhOWiIKeLu7tl9HFzKXfKCQTNKzgA== +"@nuxtjs/auth@^4.8.4": + version "4.8.4" + resolved "https://registry.yarnpkg.com/@nuxtjs/auth/-/auth-4.8.4.tgz#f1ef1ae7c94851d107a2b10179c549fd1b3ca791" + integrity sha512-47Y1nJSa9Ra/ltsduBY2XJ4hpi35+c4f1eGDO/0qV5z/4MJSLCmDf3f0xMzhrjDAfvutClz76RSty7QL9EVAqw== dependencies: "@nuxtjs/axios" "^5.6.0" body-parser "^1.19.0" @@ -1018,7 +1018,7 @@ is-https "^1.0.0" js-cookie "^2.2.1" lodash "^4.17.15" - nanoid "^2.1.0" + nanoid "^2.1.1" "@nuxtjs/axios@^5.6.0": version "5.6.0" @@ -3941,10 +3941,10 @@ eslint-visitor-keys@^1.1.0: resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-1.1.0.tgz#e2a82cea84ff246ad6fb57f9bde5b46621459ec2" integrity sha512-8y9YjtM1JBJU/A9Kc+SbaOV4y29sSWckBwMHa+FGtVj5gN/sbnKDf6xJUl+8g7FAij9LVaP8C24DUiH/f/2Z9A== -eslint@^6.3.0: - version "6.3.0" - resolved "https://registry.yarnpkg.com/eslint/-/eslint-6.3.0.tgz#1f1a902f67bfd4c354e7288b81e40654d927eb6a" - integrity sha512-ZvZTKaqDue+N8Y9g0kp6UPZtS4FSY3qARxBs7p4f0H0iof381XHduqVerFWtK8DPtKmemqbqCFENWSQgPR/Gow== +eslint@^6.4.0: + version "6.4.0" + resolved "https://registry.yarnpkg.com/eslint/-/eslint-6.4.0.tgz#5aa9227c3fbe921982b2eda94ba0d7fae858611a" + integrity sha512-WTVEzK3lSFoXUovDHEbkJqCVPEPwbhCq4trDktNI6ygs7aO41d4cDT0JFAT5MivzZeVLWlg7vHL+bgrQv/t3vA== dependencies: "@babel/code-frame" "^7.0.0" ajv "^6.10.0" @@ -6626,7 +6626,7 @@ nan@^2.12.1, nan@^2.14.0: resolved "https://registry.yarnpkg.com/nan/-/nan-2.14.0.tgz#7818f722027b2459a86f0295d434d1fc2336c52c" integrity sha512-INOFj37C7k3AfaNTtX8RhsTw7qRy7eLET14cROi9+5HAVbbHuIWUHEauBv5qT4Av2tWasiTY1Jw6puUNqRJXQg== -nanoid@^2.1.0: +nanoid@^2.1.1: version "2.1.1" resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-2.1.1.tgz#524fd4acd45c126e0c87cd43ab5ee8346e695df9" integrity sha512-0YbJdaL4JFoejIOoawgLcYValFGJ2iyUuVDIWL3g8Es87SSOWFbWdRUMV3VMSiyPs3SQ3QxCIxFX00q5DLkMCw== @@ -10294,7 +10294,7 @@ uuid@^3.2.1, uuid@^3.3.2: resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.3.2.tgz#1b4af4955eb3077c501c23872fc6513811587131" integrity sha512-yXJmeNaw3DnnKAOKJE51sL/ZaYfWJRl1pK9dr19YFCu0ObS231AB1/LbqTKRAQ5kw8A90rA6fr4riOUpTZvQZA== -v-calendar@^1.0.0-beta.14: +v-calendar@^1.0.0-beta.16: version "1.0.0-beta.16" resolved "https://registry.yarnpkg.com/v-calendar/-/v-calendar-1.0.0-beta.16.tgz#5dbf46c7cfe681ea403334f1e333f4feb6a68155" integrity sha512-k91PnjAVygnHTZPJS8jjvYOfUNmULYf50c9MjOG4tVXqVNYwbFlUZXjLaZQuXQEEEo3HIkGAQSjskoQPrppaVg== @@ -10388,10 +10388,10 @@ vue-hot-reload-api@^2.3.0: resolved "https://registry.yarnpkg.com/vue-hot-reload-api/-/vue-hot-reload-api-2.3.3.tgz#2756f46cb3258054c5f4723de8ae7e87302a1ccf" integrity sha512-KmvZVtmM26BQOMK1rwUZsrqxEGeKiYSZGA7SNWE6uExx8UX/cj9hq2MRV/wWC3Cq6AoeDGk57rL9YMFRel/q+g== -vue-i18n@^8.14.0: - version "8.14.0" - resolved "https://registry.yarnpkg.com/vue-i18n/-/vue-i18n-8.14.0.tgz#613cbbc21d71dc608cd085f8a94ea3a40badcd33" - integrity sha512-utI1Rvc8i+fmmUkkKRmHaf4QQ87s7rGVL5ZZLsKvvRzmgaIr1l+GfGxxxRmsZxHpPlgeB8OxoUZ4noqZgDL6xg== +vue-i18n@^8.14.1: + version "8.14.1" + resolved "https://registry.yarnpkg.com/vue-i18n/-/vue-i18n-8.14.1.tgz#0ca0a2742c14e0144481655157fffcc7cc313e50" + integrity sha512-uHzw5GTFyf/TmjJXveSl3L4CG61KI4lvhKOQvx8W4Y8P2LZ3v3l/qw4KRs1C6pWyjkfY9p0rezYNFO5YzMEQ8A== vue-loader@^15.7.1: version "15.7.1" @@ -10523,10 +10523,10 @@ webpack-bundle-analyzer@^3.4.1: opener "^1.5.1" ws "^6.0.0" -webpack-cli@^3.3.8: - version "3.3.8" - resolved "https://registry.yarnpkg.com/webpack-cli/-/webpack-cli-3.3.8.tgz#caeaebcc26f685db1736e5decd3f01aac30123ec" - integrity sha512-RANYSXwikSWINjHMd/mtesblNSpjpDLoYTBtP99n1RhXqVI/wxN40Auqy42I7y4xrbmRBoA5Zy5E0JSBD5XRhw== +webpack-cli@^3.3.9: + version "3.3.9" + resolved "https://registry.yarnpkg.com/webpack-cli/-/webpack-cli-3.3.9.tgz#79c27e71f94b7fe324d594ab64a8e396b9daa91a" + integrity sha512-xwnSxWl8nZtBl/AFJCOn9pG7s5CYUYdZxmmukv+fAHLcBIHM36dImfpQg3WfShZXeArkWlf6QRw24Klcsv8a5A== dependencies: chalk "2.4.2" cross-spawn "6.0.5"