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

mathewberry's avatar

Unable to validate user is logged in in vue using Laravel airlock SPA auth

I have installed Laravel Airlock and created a single page app separately using Vue CLI with vue router.

The authentication for SPA is working perfectly, I’m able to initialise a csrf token and login using the standard Laravel endpoint.

However I am struggling to understand how to check if the session is active.

For example if a user is on the dashboard and the session is cleared or the session times out, what is the solution for identifying this in vue?

My thoughts are having a global axios filter catch for any 401s then automatically redirect to login. Another option is to do an Ajax call on every request to check the user is logged in.

When a user logs in it currently just sets a local storage var so the vue router can check if their logged in but atm I can’t check if they’re actually logged in.

I’m not using tokens as the documentation stated that if you’re doing a first party SPA then there is no requirement.

0 likes
3 replies
mathewberry's avatar

After doing more research the best solution at the moment looks to be using an interceptor and listen for the 401 status on any unauthenticated api calls.

paddelboot's avatar

I am facing the same problem. Seems like a very basic requirement for a SPA to redirect to login if a user with no session tries to access a protected view.

@mathewberry Can you provide some details for your solution? Thanks.

Please or to participate in this conversation.