{"action":"created","issue":{"url":"https://api.github.com/repos/nuxt/nuxt.js/issues/1742","repository_url":"https://api.github.com/repos/nuxt/nuxt.js","labels_url":"https://api.github.com/repos/nuxt/nuxt.js/issues/1742/labels{/name}","comments_url":"https://api.github.com/repos/nuxt/nuxt.js/issues/1742/comments","events_url":"https://api.github.com/repos/nuxt/nuxt.js/issues/1742/events","html_url":"https://github.com/nuxt/nuxt.js/issues/1742","id":261042109,"number":1742,"title":"How add Authorization token in axios header?","user":{"login":"vUdav","id":7684712,"avatar_url":"https://avatars2.githubusercontent.com/u/7684712?v=4","gravatar_id":"","url":"https://api.github.com/users/vUdav","html_url":"https://github.com/vUdav","followers_url":"https://api.github.com/users/vUdav/followers","following_url":"https://api.github.com/users/vUdav/following{/other_user}","gists_url":"https://api.github.com/users/vUdav/gists{/gist_id}","starred_url":"https://api.github.com/users/vUdav/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vUdav/subscriptions","organizations_url":"https://api.github.com/users/vUdav/orgs","repos_url":"https://api.github.com/users/vUdav/repos","events_url":"https://api.github.com/users/vUdav/events{/privacy}","received_events_url":"https://api.github.com/users/vUdav/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2017-09-27T16:38:54Z","updated_at":"2017-09-27T16:58:45Z","closed_at":null,"author_association":"NONE","body":"When I login, I'm get from remote API server user token. When I get token, I'm set him on store and local storage. If I reload my app I want get my token from local storage and set on store. But local storage not defined if I call them on my store:\r\n```javascript\r\nimport Vue from 'vue'\r\nimport Vuex from 'vuex'\r\n\r\nVue.use(Vuex)\r\n\r\nconst store = () => new Vuex.Store({\r\n  user: {\r\n    token: localStorage.getItem('userToken')\r\n  }\r\n})\r\n```\r\n\r\nor ~plugins/axios.js:\r\n```javascript\r\nimport axios from 'axios'\r\n\r\nexport default axios.create({\r\n  baseURL: process.env.baseApiUrl,\r\n  headers: {\r\n    'Authorization': 'Bearer '+localStorage.getItem('userToken')\r\n  }\r\n})\r\n```\r\n\r\nHow can I resolve this problem?\r\n\r\nP.S. sorry for my English"},"comment":{"url":"https://api.github.com/repos/nuxt/nuxt.js/issues/comments/332587371","html_url":"https://github.com/nuxt/nuxt.js/issues/1742#issuecomment-332587371","issue_url":"https://api.github.com/repos/nuxt/nuxt.js/issues/1742","id":332587371,"user":{"login":"homerjam","id":1055769,"avatar_url":"https://avatars2.githubusercontent.com/u/1055769?v=4","gravatar_id":"","url":"https://api.github.com/users/homerjam","html_url":"https://github.com/homerjam","followers_url":"https://api.github.com/users/homerjam/followers","following_url":"https://api.github.com/users/homerjam/following{/other_user}","gists_url":"https://api.github.com/users/homerjam/gists{/gist_id}","starred_url":"https://api.github.com/users/homerjam/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/homerjam/subscriptions","organizations_url":"https://api.github.com/users/homerjam/orgs","repos_url":"https://api.github.com/users/homerjam/repos","events_url":"https://api.github.com/users/homerjam/events{/privacy}","received_events_url":"https://api.github.com/users/homerjam/received_events","type":"User","site_admin":false},"created_at":"2017-09-27T16:58:44Z","updated_at":"2017-09-27T16:58:44Z","author_association":"CONTRIBUTOR","body":"`localStorage` is a client side API, you can determine if the code should run using the context passed to plugins eg.\r\n\r\n```js\r\nexport default ({ isClient }) => {\r\n  // do codez\r\n}\r\n```\r\n\r\nOr a better solution would probably be to use the nuxt-modules/axios library which optimises axios for use within nuxt."}}
{"actor":{"display_login":"homerjam"}}