<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Anujmgr</title>
    <description>The latest articles on DEV Community by Anujmgr (@anujmgr).</description>
    <link>https://dev.to/anujmgr</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F628980%2Fb9b3ca06-3a50-431b-a6e1-06fd64cf54b4.png</url>
      <title>DEV Community: Anujmgr</title>
      <link>https://dev.to/anujmgr</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/anujmgr"/>
    <language>en</language>
    <item>
      <title>Implementing JWT Auth in Laravel and React with Secure Token Rotation: Intro</title>
      <dc:creator>Anujmgr</dc:creator>
      <pubDate>Tue, 01 Jul 2025 08:55:00 +0000</pubDate>
      <link>https://dev.to/anujmgr/jwt-with-refresh-token-rotation-using-laravel-passport-1hkp</link>
      <guid>https://dev.to/anujmgr/jwt-with-refresh-token-rotation-using-laravel-passport-1hkp</guid>
      <description>&lt;p&gt;In this series, we’ll walk through setting up &lt;strong&gt;JWT authentication with refresh token rotation&lt;/strong&gt; using &lt;strong&gt;Laravel Passport&lt;/strong&gt;. And implement it in our react js application with secure token rotation.&lt;/p&gt;

&lt;h3&gt;
  
  
  What will our flow look like?
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;User logs in&lt;/strong&gt;&lt;br&gt;
The client sends login credentials to the server.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Server responds with tokens&lt;/strong&gt;&lt;br&gt;
The server generates an &lt;code&gt;accessToken&lt;/code&gt; and a &lt;code&gt;refreshToken&lt;/code&gt;, and sets them in cookies (&lt;code&gt;HttpOnly&lt;/code&gt; for refresh token to prevent XSS attacks).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Redux stores accessToken in memory&lt;/strong&gt;&lt;br&gt;
For fast access and to avoid exposing it in localStorage.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Attach token to every request&lt;/strong&gt;&lt;br&gt;
On each API call, Redux middleware or interceptor appends the &lt;code&gt;accessToken&lt;/code&gt; as a Bearer token in the &lt;code&gt;Authorization&lt;/code&gt; header.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Handle unauthorized (401) responses&lt;/strong&gt;&lt;br&gt;
If the access token has expired, the client uses the &lt;code&gt;refreshToken&lt;/code&gt; to request a new &lt;code&gt;accessToken&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Token rotation&lt;/strong&gt;&lt;br&gt;
If the &lt;code&gt;refreshToken&lt;/code&gt; is valid, the server sends back a new pair of tokens (access + refresh) — rotating the &lt;code&gt;refreshToken&lt;/code&gt; to minimize abuse if stolen.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Redirect on failure&lt;/strong&gt;&lt;br&gt;
If the &lt;code&gt;refreshToken&lt;/code&gt; is invalid or expired, the user is logged out and redirected to the login page.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>laravel</category>
      <category>jwt</category>
      <category>auth</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
