Reputation: 693
I just did the Auth system through Laravel and I'm facing a problem : how to check in ReactJS the logged user? I need to get his ID to check if this user can modify the page. I don't know where to go at all.
Any tips would be welcome!
Upvotes: 1
Views: 3395
Reputation: 1733
you can't use the default authentication (using sessions) with a react app.
what you need is a system that creates an authentication token ( search for JWT or Laravel passport ) which identifies users, and since the HTTP protocol is stateless, in each request you must send that token to you backend service / API.
you can of course add a value representing the authentication ( true if you got a valid token ) to your global state just for UI or routing purpose.
check this medium article where the author explains how to create a token based auth with laravel using JWT.
you can also search about REST and oauth for more information.
Upvotes: 1