Laravel 5.1 + Vue.js - vue-router beforeEach AuthService

Let's say I want to create an AuthService in vue-router to check the current session before moving on to the next route, for example, an example:

http://vuejs.imtqy.com/vue-router/en/api/before-each.html

router.beforeEach(function ({ to, next }) {
  if (to.path === '/auth-required') {
    // return a Promise that resolves to true or false
    return AuthService.isLoggedIn()
  } else {
    next()
  }
})
  • How can I use this to use Laravel 5.1 without using JSON Web Tokens (JWT)?
  • Is there a "best estimate" approach for SESSION_DRIVER in Laravel, for example. Redis, for this scenario?

I searched the Internet many times but never saw attempts to authenticate a session using vue-router without JWT.

+4
source share
1 answer

isLoggedIn() auth if. auth , . if . beforeEach " , ?" if.

router.beforeEach(function (transition) {
    if (transition.to.auth && !AuthService.isLoggedIn()) {
        // if route requires auth and user isn't authenticated
        transition.redirect('/login')
    } else {
        transition.next()
    }
})

" , " , isLoggedIn() . , , , ? JWT. , .

Laravel 5.1 JSON Web (JWT)?

JWT, API. API Laravel str_random(). 1 . 2- : 1. URL- api_token = XXX 2. ": XXX".

, Vue.js, vue-resource :

Vue.http.headers.common['Authorization'] = 'Bearer ' + token;

API.

" " SESSION_DRIVER Laravel, . Redis, ?

100% , , API. -, /.

+1

Source: https://habr.com/ru/post/1628851/


All Articles