How to store JWT token properly using Laravel 5.4 and Vue.js 2 - development

How to store JWT token properly using Laravel 5.4 and Vue.js 2

I’m writing an API using Laravel 5.4 and connect to it from frontend written in Vue.js 2. After login API gets back a token to me, so how and where should I store the token in a frontend? Now, I’m using localStorage for that but it doesn’t seem to be a right way.

This is how I check for token:

router.beforeEach((to, from, next) => {
  if(to.meta.requiresAuth) { 
    if(store.getters.logged || window.localStorage.getItem('access_token')) { 
      next();
    }
    else {
      next('/login');
    }
  }
  else {
    next();
  }
});



from Laravel Questions and Answers https://laravelquestions.com/laravel/how-to-store-jwt-token-properly-using-laravel-5-4-and-vue-js-2/
via Lzo Media

Comments

  1. Hi, ExpressTech laravel Development Service provide fluency in delivering simple code for a variety of bundles to help create effective and Secure websites for Various fields of industry and domains. We help businesses to achieve their estimated goals using leading solutions from the Laravel framework.

    ReplyDelete

Post a Comment

Popular posts from this blog

ng-show doesn’t work correct with value boolean

ng-include of inline SVG does not display gradient except in Chrome

Using PHP and MySQL data to generate PDF letters like in MS Word mailmerge functionality - development