Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

hetunandu's avatar

Authenticating user on the client with laravel and JWT

This is my current setup:

I have a restful backend which authenticates users via JWT. Made in Laravel

I have a web client made in Laravel that communicates with the backend via curl in the controllers.

Also an android app.

I have a login route where the client sends the email and password and if all is cool i send them the token.

For accessing properties that needs authorisation, the client has to send the token with the request and server respond accordingly.

The problem is: I want to save the authenticated user somehwere in the client so that I do not have to ask for the user data to the server again and again. I am saving the token as a cookie. I need the client to know it is authenticated the current user so that if he goes to another page, the user still sees that he is logged in.

What solution i can think of: Save the user data as a cookie too. So that i can check for the cookie and display user related stuff accordingly in the web client.

But I am not happy with this. For some reason I think it is wrong. Is there a better way to handle authentication from the client side with Laravel? Can i use functions like auth::user() ?

0 likes
0 replies

Please or to participate in this conversation.