0

I am new to feathers and vue js I don't understand this, when i log in a user the v-if directives works on the navbar, but when i refresh the page i notice that the user is no longer logged in still the JWT is stored in the localStorage.

App-Navbar.vue

<template>
  <div>
    <q-header bordered class="bg-white">
      <q-toolbar>
        <div class="q-gutter-sm" v-if="!user">

          <q-btn to="/login" />
          <q-btn to="/signup" />

        </div>
        <div class="q-gutter-sm" v-if="user">

          <q-btn @click="logout"/>
        </div>

      </q-toolbar>
    </q-header>
  </div>
</template>

<script>
import { mapActions, mapState } from "vuex";

export default {

methods: {
    ...mapActions("auth", { authLogout: "logout" }),
    logout() {
      this.authLogout().then(() => this.$router.push("/login"));
    }
  },
  computed: {
    ...mapState("auth", { user: "payload" })
  }
};
</script>
seddka
  • 105
  • 12

1 Answers1

0

You just need some logic to fetch your token on refresh. You will first need to save it somewhere, let's say sessionStorage.

You can use vuex-persistedstate as you mentioned, but a lighter solution would be just setting your user property in the state of the store like this

user: sessionStorage.getItem(yourkey) ?? null
Cristiano Soleti
  • 805
  • 7
  • 12