You can for example add the user_id and some other information (is_admin, email, ...) in the encrypted session cookie with token: jwt.sign(...). You can use the js-cookie package.
Laravel Sanctum API & React: securely check if user is logged in
Hi, I followed this tutorial https://laravel-news.com/using-sanctum-to-authenticate-a-react-spa to create a simple app using Laravel Sanctum and React. Everything worked out pretty good. However, this tutorial and many others tend to store user details such as userId, email and isLoggedIn (as boolean), using sessionStorage or localStorage. Before getting access to sensitive routes and data it is checked whether isLoggedIn is true for example. This does not seem very secure to me, since users may set these values themselves within the developer console.
I'm aware that the auth:sanctum middleware secures sensitive API endpoints server side, however, users could easily get access to the members only area. So, is there a best-practice to securely check if a user is logged in before accessing protected routes?
Please or to participate in this conversation.