1
votes

I implement Sanctum in my project. I store the token in my localstorage and add it to the header in all requests. Everything works ok but I want to add a login component in the separate route and if the user is logged in, display the page, if not - redirect to the login page. How can I do tak? I thought checking the token exists in localstorage but it doesn;t safe method. User can add to localstorage everything and display the page but he can't do something else in order to protect the api by sanctum:auth. How can I solve my problem?

1
I believe there is sanctum:auth middlware that checks if a user is logged in or directs them to a login page (which you can change)Cameron

1 Answers

0
votes

Make a route in your Laravel that will return current logged in user data make a request to that route as soon as your front end is mounted if it returns your expected status and the user data you're good to go else you know the token is not valid and you have to redirect the user to the login page