Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 138221

NuxtJS set Cookie in Middleware

$
0
0

I'm building a nuxtjs app and try to set a cookie from a global middleware. I found this contribution on GitHub which shows a method to do this.

So I implemented my middleware like this

export default function ({ isServer, res, query }) {
  if (query.lang) {
    if (isServer) {
      res.setHeader("Set Cookie", [`lang=${query.lang}`]);
    } else {
        document.cookie = `lang=${query.lang}`;
    }
  }
}

My problem is that when I visit my app with ?lang=xxx as a parameter, I'm always running into the else block of my if condition. So I get the error

document is not defined

Has anyone a idea what is wrong with my code. I can't see a difference to the code published on github.


Viewing all articles
Browse latest Browse all 138221

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>