Hello,
I have an application (personal project) I had developed with VueJS2, axios and VueX. I now want to develop it with VueJS 3, axios and pinia. The back is with Laravel, I use Fortify for the authentication and the API endpoint are protected with Sanctum.
In the first application all works fine, but it was also my first VueJS front application so I had some bad code because it was my first steps into VueJS. But it does the job.
I have an API service (authApi) with 3 methods : login(user), logout() and getAuthenticated().
I have a Login component for the login view.
And the user can logout from the App.vue component where there is the main menu.
What I need is advice to organize all my authentication code.
According to me, pinia shouldn't have to login or logout a user, pinia should only have to store some data to be shared with the entire application (I say this because I have seen several example on the web with some business code for authentication inside a pinia store). But I'm perhaps wrong.
And I need to use pinia to persist the authentication even if a user refreshes manually the browser. For the moment I persisted the authentication with a property in the session storage. And if the user refreshed the browser manually, I read the session storage and if true I checked the authentication via a query to the backend. What can I do other and better ?
Can you advise me please how to organize the authentication code in the frontend ?
Thanks a lot.
V