title: Using JWT saved in cookies in vue.js to get a user object from my spring API for persisted log-in
body: <p>I'm trying to mock up some persisted log-in for my first web application so the site is still functional after a refresh. When I print the token (which is saved in cookies) in the console, it prints normally.  And when I use postman with the token in the header, I get the correct JSON response.  However, when using it in the mounted method, I get a 401.  So I believe it is an issue with the way I'm am implementing my headers in my fetch.  Thanks in advance, as I am extremely new to coding.</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>mounted: function() {
      console.log(this.$cookies.get('token'));
      let t = JSON.parse(JSON.stringify(this.$cookies.get('token')));
      let h = new Headers();
      h.append('Authentication', `Bearer ${t}`);
      fetch('http://localhost:8080/api/owner/persist', {
          method: 'GET',
          headers: h
        })
        .then((response) =&gt; {
          return response.json();
        })
        .then((data) =&gt; {
          this.jwtUser = data;
        })</code></pre>
  </div>
  </div>
  </p>
  <p>Java Controller below: if I have the PreAuthorize Tag, I get a 401 error,  and if I take it away I get a null pointer exception.  I think its just something wrong with the formatting of my header.  Which I have been messing around with a lot.</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>    @PreAuthorize("isAuthenticated()")
      @RequestMapping(path = "api/owner/persist", method = RequestMethod.GET)
      public Owner persistedLogin(Principal principal) {
          Owner o = new Owner();
          o = ownerDAO.getOwnerInfoByName(principal.getName());
          return o;
      }</code></pre>
  </div>
  </div>
  </p>