1

I finally implemented my Laravel-vue js Authentication using passport API I already getting the token and api/user requests. Before I understand I tried to authenticate using the normal process, so I just pass the the data POST to /login by that I am authenticated and got a $_SESSION.

Eventually after I finish implementing passport API I notice that when I attempt to authenticate session doesn't start anymore so I tried to change the middleware to api doesn't work either. So my question are,

  • Do I still need to depend on session or its the access_token will take care of the communication to backend?
  • Session not starting anymore after implementing the API Auth, is it normal? So I authenticate, I got the tokens and user details but doesn't have session in backend.

1 Answer 1

3

The thing is if you are developing your backend to provide API (REST Service) to serve to your client side application then you dont need session.

If all of your routes are under API AUTH middleware then you can use those routes to get data from the backend services using access_token and you dont need SESSION actually.

If your routes (Those which provides data to your client app) are under web and auth middleware, you need to have SESSION to call these routes and get data.

I want to say in simple word that is all depends on your routes and architecture. If you want to develop SPA (Single page application) or JS powered application then ofcourse you need all the routes under API and API AUTH and Passport provides this out of the box.

Finally, if your routes are under
'middleware' => 'auth:api'
then access_token is enough to call those routes and get data, where you dont need SESSION.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, this is my first time building JS framework really helpful. I actually made entering in protected routes using this laravel.com/docs/5.5/passport#passing-the-access-token is this right?
yes thats correct, i will add more detail on my post and update the answer when i get time. i have sample steps and code that i can post with this answer later. Laravel is really has capabilities to serve Single page applications using VueJS or Angular or any other js frameworks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.