Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mvoit's avatar
Level 2

Authentication in views when using Passport

Hi!

I am using Passport for my REST-Api. I have a SPA (Vue.js) and the login form posts my credentials to the server, which sends the token back. The token is then stored in localStorage and submitted in each AJAX header.

So far so good. But as soon as the user reloads the page, instead of routing with Vue, I make a full page request on my server, with no token whatsoever because this is no longer an AJAX call. Hence, in my view, the user always appears to be logged out.

Unfortunately, I am stuck in a situation, where I need user info on page rendering already.

How do you combine passport tokens and authentication in views? Do I need to keep the default authentication for web routing and do a login? And once I logged in, I do a secondary login in my API to retrieve the token?

Thanks!

0 likes
0 replies

Please or to participate in this conversation.