Is the ‘isAuthenticated’ a getter in the pinia store? #2 is 100% the way to go here and should work on if it’s a getter method.
Sep 29, 2023
4
Level 63
Watching for a modification in a pinia store
Hello,
I have this code.
const authStore = useAuthStore()
let isAuthenticated = ref(authStore.isAuthenticated)
watch(
() => authStore.isAuthenticated,
() => {
isAuthenticated = authStore.isAuthenticated
},
)
....
<router-link to="/login" v-if="!isAuthenticated.value">
<v-btn icon="fa:fas fa-right-to-bracket" color="white"></v-btn>
</router-link>
<v-btn @click="logout" icon="fa:fas fa-right-from-bracket" color="white" v-if="isAuthenticated.value"></v-btn>
// OR
<router-link to="/login" v-if="!authStore.isAuthenticated">
<v-btn icon="fa:fas fa-right-to-bracket" color="white"></v-btn>
</router-link>
<v-btn @click="logout" icon="fa:fas fa-right-from-bracket" color="white" v-if="authStore.isAuthenticated"></v-btn>
And I'm quite sure that the watch is not useful. However no one works. For example with both codes the icon doesn't change.
What am I doing wrong ?
Can you help me with some suggestions ?
Thanks a lot.
V
Level 1
1 like
Please or to participate in this conversation.