I'm wondering what would be the best way to retrieve the currently logged in user from the database when using Laravel strictly for it's built in user login and it's API. I've read that session does not work with API route and I'm not sure if creating a token for the user upon login is the right solution. If I understand correctly this would be easy to do with Auth but since I'm using React on the front end, it's a bit trickier.
My thought process would be to update the timestamp of that user's record in the database upon login and in the User controller, retrieve the record with the most recent timestamp, which would be that user, then return that user as a JSON object which I could access through the API URL endpoint on the frontend. I'm not sure though.
Any help or insight would be great. Thanks
There's a documentation entry on this one. https://laravel.com/docs/5.8/passport
Is your requirement to a list of current logged in users? Or are you looking for an equivalent of
$user = Auth::user();?