I have a button in the navigation bar that only appears when a user is logged in. However, I noticed that the button does not disappear or appear immediately when the user logs out or logs in. I have included my code below: Button:
<div v-if="loggedIn">
<div class="w-2/12 hidden lg:flex" v-for="(data, index) in allLoggedInUsers" :key="index">
<button @click="logout" class="downloadbtn">r;
{{ data.logoutButton }}
</button>
</div>
</div>
In data:()
, the value for loggedIn
is set to false.
loggedIn: false
To update whether the user is logged in or not, I created a mounted()
function:
mounted() {
const user = firebase.auth().currentUser;
if(user) {
this.loggedIn = true;
}
},
Just to note, I have imported Firebase and Firebase/auth libraries, and allLoggedInUsers
is a GraphQL query I am using.