p0t4t0
8 months ago

What's a better way to detect a user is logged in on a Laravel front end with a React CMS back end that utilizes token based auth?

Posted 8 months ago by p0t4t0

Hi folks might not be the best way to handle this but right now I have a Laravel app that serves as a front end for my app as well as an API server and a React app that acts a CMS, it all works and functions correctly but whenever I am on the home page "/" there is a navbar and either a login button to the top right corner or the user's name if he's logged in, my current approach is to just check whether I have a token stored in localStorage and the user data to know whether or not the user is logged in but I can't seem to shake the feeling that there is a much better solution

Basically my app works as follows:

  1. I have some routes set up with Laravel (page reloads, not a SPA)
  2. Other routes I use React Router (for the CMS, no page reloads, SPA)
  3. I am using a token based approach to authenticate/authorize users

PS might be worth mentioning that i am using a token based approach with my authentication

Please sign in or create an account to participate in this conversation.