Cobra braisé
Cobra braisé

Reputation: 109

How to remove global sidebar when not logged in (vuetify)

I would like to remove my sidebar (menu) from the login and register page. But this sidebar is global so I can't juste hide it. Is there a way inside the sidebar file himself to check if user is connected like using cookie ?

I'm using vuex and vuetify and router.

The fact is that my sidebar crashes because when there is no data inside the request for user (not connected), the sidebar can't be shown.

computed: {
      ...mapGetters(['getUserData']), //It's null when not logged in

I would like to check if the user is connected before I do any request, so I'm supposed to remove the mapGetters from the computed method and to do it later, no ?

Thanks for your answers.

Upvotes: 1

Views: 1064

Answers (1)

Emre Arabaci
Emre Arabaci

Reputation: 448

As I understand it, you want hide some component, button or link (whichever you are using) if user not logged in.

Try this if user not logged in and you want hide:

<componentName v-if="!getUserData" />

I use two sidebar for logged and not logged users.

My project:

// Component File (filename.vue)
<template>
    <v-navigation-drawer v-if="user">
    //...
    </v-navigation-drawer>

    <v-navigation-drawer v-if="!user">
    //...
    </v-navigation-drawer>
</template>


computed: {
        ...mapGetters(['isLoggedIn']),
        ...mapGetters(['user'])
    },

I'm also trying to learn. I hope my answer is correct and it works.

Upvotes: 2

Related Questions