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

dam28800's avatar

Laravel sanctum API, retrieve the token for use in view components

Hello,

Here is the context. I have two sites using the same domain.

The first using Laravel and view components The second is an "API", I use Laravel Sanctum. This API has a single user. Later, there will be a third site using this same API as well.

The API authentication system works perfectly. When I switch from Postman my user, my token is returned.

I'm wondering about token retrieval and usage on my first site using vue components.

My idea was to store API user login credentials in my .env file and retrieve the token in controllers where I use vue components.

Another solution would be to fetch my token on each call to the API, but that could be cumbersome.

Finally store the token at the user's connection and reuse it but where to store it, in session, in cookies,... Security level is not ideal.

Thanks in advance for your ideas.

0 likes
1 reply

Please or to participate in this conversation.