sara97
sara97

Reputation: 401

Vue JS: check if user logged in not working in my code

in my Vue Js project i wanted to check if user logged in so he can access website and if not it should take him to /login page.. since i'm new to Vue Js i tried the below code but it didn't work in app.js, can someone please help me in this ?

  mounted: function(){
       if(JSON.parse(sessionStorage.user)){
          console.log(JSON.parse(sessionStorage.user))
        }
    }

Upvotes: 0

Views: 794

Answers (1)

akshatsri
akshatsri

Reputation: 26

You need to get the value from sessionStorage. Something like this would work

sessionStorage.getItem('name of the key')

Upvotes: 1

Related Questions