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

amitshahc's avatar

How to pass X-XSRF-TOKEN in every web based response using JWT?

Hello,

I just replaced the API token package from laravel/passport to tymon/jwt-auth to implement the multi-table auth. everything working fine.

but now i am looking for the way to attach X-XSRF-TOKEN header in each web response so that I can make an ajax call from the web UI React app and check the authentication. the laravel/passport had a way to do that by adding a line in kernel.php.

Please don't tell me to pass in the URL query string.

0 likes
2 replies
amitshahc's avatar

But what exact place should I generate the token and keep retaining the same token in subsequent responses without keeping regenerating new tokens for each response?

and what are the methods to generate() (maybe I know this) and get the current/already generated token (this I don't know)?

Ultimately, I am looking for the same approach that the Laravel/Passport's CreateFreshApiToken does. it sets the X-XSRF-Token in the response header I guess.

Please or to participate in this conversation.