title: How to use localStorage in Nuxt.js store
body: <p>I'm working on a nuxt.js project.here, i want to use <code>localStorage</code> inside <code>Nuxt-Store</code> and also want to access the <code>localStorage</code> value from <code>Nuxt-Middleware</code>. it's show an error.</p>
  
  <blockquote>
    <p>localStorage is not defined.</p>
  </blockquote>
  
  <p>How can i solve this problem ?</p>
  
  <p>Here, code sample of <strong><code>store/index.js</code></strong></p>
  
  <pre><code>setUser(state, { user }){
      state.user = user
      state.isLoggedIn = true
      localStorage.setItem('user', JSON.stringify(user));
      localStorage.setItem('isLoggedIn', state.isLoggedIn);
  },
  </code></pre>
  
  <p>my <strong>middleware</strong> code is here- </p>
  
  <pre><code>export default function({ store, redirect, route}) {
  const user = localStorage.getItem('user');
  const loggedStatus = store.getters['isLoggedIn']
  
  if (user) {
      if(route.path == '/login' || route.path == '/user/temporary'){
          return redirect('/')
      } 
         return 
  }
  
  
  if(!user){
      return redirect('/login')
  }
  
  }
  </code></pre>