<?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: jatin</title>
    <description>The latest articles on DEV Community by jatin (@chaudharyjatin205).</description>
    <link>https://dev.to/chaudharyjatin205</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%2F2387613%2Fb1553641-8cf1-43d1-b028-2d25abe1793e.jpeg</url>
      <title>DEV Community: jatin</title>
      <link>https://dev.to/chaudharyjatin205</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/chaudharyjatin205"/>
    <language>en</language>
    <item>
      <title>YES I AM THE ONE WHO REQUESTED THE ACCESS</title>
      <dc:creator>jatin</dc:creator>
      <pubDate>Mon, 15 Dec 2025 23:47:11 +0000</pubDate>
      <link>https://dev.to/chaudharyjatin205/yes-i-am-the-one-who-requested-the-access-3965</link>
      <guid>https://dev.to/chaudharyjatin205/yes-i-am-the-one-who-requested-the-access-3965</guid>
      <description>&lt;p&gt;&lt;strong&gt;NOTE : This is my first post, so apologies in advance if I’ve misunderstood something.I’m open to discussions and corrections&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;Have u guys ever feel the magic of authorization and secure information transfer (via signing) like which resource is allowed for your use and what is not under your access or u want to transfer sensitive information then how we know that they have encrypted them or not&lt;/p&gt;

&lt;p&gt;WELL, JWT is widely used in modern web applications&lt;/p&gt;

&lt;h2&gt;
  
  
  What is JWT?
&lt;/h2&gt;

&lt;p&gt;JWT stands for JSON Web Tokens defines a compact and self-contained way for securely transmitting information between parties as a JSON object.This information can be verified and trusted because it is digitally signed.&lt;/p&gt;

&lt;p&gt;JWT are short lived they expire after some time which make them special.&lt;/p&gt;

&lt;p&gt;Signed tokens can verify the integrity of the claims contained within it, while encrypted tokens hide those claims from other parties.&lt;/p&gt;

&lt;h2&gt;
  
  
  USE OF JWT ?
&lt;/h2&gt;

&lt;p&gt;JWT is majorly used in authorization and information exchange&lt;br&gt;
1&amp;gt;Authorization: it is most common use case of JWT . it is related to access routes, services, and resources that are permitted with that token. there is a difference between authentication and authorization well both use jwt but authentication is like you want to verify the user but authorization is related to access to resources.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Authentication → verifies who the user is&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Authorization → determines what the user is allowed to access&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;2&amp;gt;Information Exchange: It is like securely transmitting information between parties. Because JWTs can be signed—for example, using public/private key pairs—you can be sure the senders are who they say they are.&lt;/p&gt;
&lt;h2&gt;
  
  
  Structure of JWT ?
&lt;/h2&gt;

&lt;p&gt;A JWT consists of three parts, separated by dots (.):&lt;/p&gt;

&lt;p&gt;1&amp;gt; HEADER: Contains metadata about the token&lt;br&gt;
&lt;code&gt;{&lt;br&gt;
  "alg": "HS256",&lt;br&gt;
  "typ": "JWT"&lt;br&gt;
}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;2&amp;gt; Payload: Contains the actual data (claims)&lt;br&gt;
&lt;code&gt;{&lt;br&gt;
  "userId": 123,&lt;br&gt;
  "email": "user@example.com",&lt;br&gt;
  "role": "admin",&lt;br&gt;
  "exp": 1712345678&lt;br&gt;
}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;3&amp;gt;Signature: Used to verify that the token was not tampered with.&lt;br&gt;
&lt;code&gt;HMACSHA256(&lt;br&gt;
  base64UrlEncode(header) + "." + base64UrlEncode(payload),&lt;br&gt;
  secret_key&lt;br&gt;
)&lt;/code&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  How JWT Authentication Works (Flow)?
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;User logs in with email &amp;amp; password&lt;/li&gt;
&lt;li&gt;Server verifies credentials&lt;/li&gt;
&lt;li&gt;Server generates JWT using a secret key&lt;/li&gt;
&lt;li&gt;JWT is sent to client&lt;/li&gt;
&lt;li&gt;Client stores JWT (cookie / localStorage)&lt;/li&gt;
&lt;li&gt;Client sends JWT in Authorization header for every request&lt;/li&gt;
&lt;li&gt;Server verifies JWT and allows access&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;
  
  
  Advantages of JWT :
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Stateless authentication (no DB lookup per request)&lt;/li&gt;
&lt;li&gt;Fast &amp;amp; scalable&lt;/li&gt;
&lt;li&gt;Easy to use across microservices&lt;/li&gt;
&lt;li&gt;Works well with REST APIs &amp;amp; mobile apps&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Disadvantages of JWT :
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Token cannot be revoked easily&lt;/li&gt;
&lt;li&gt;If token is stolen, attacker gets access&lt;/li&gt;
&lt;li&gt;Payload is readable (not encrypted)&lt;/li&gt;
&lt;li&gt;Large tokens increase request size&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  JWT in Express.js :
&lt;/h2&gt;

&lt;p&gt;Generate Token&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const jwt = require("jsonwebtoken");

const token = jwt.sign(
  { userId: user._id },
  process.env.JWT_SECRET,
  { expiresIn: "1h" }
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Verify Token (Middleware)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const verifyToken = (req, res, next) =&amp;gt; {
  const token = req.headers.authorization?.split(" ")[1];
  if (!token) return res.status(401).json({ message: "No token" });

  jwt.verify(token, process.env.JWT_SECRET, (err, decoded) =&amp;gt; {
    if (err) return res.status(403).json({ message: "Invalid token" });
    req.user = decoded;
    next();
  });
};

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Final Thoughts:
&lt;/h2&gt;

&lt;p&gt;JWT is powerful, fast, and widely adopted — but only when used correctly.&lt;br&gt;
Understanding how it works internally helps in designing secure and scalable systems.&lt;/p&gt;

&lt;p&gt;I’m starting this as a learning hobby to improve my knowledge and connect with talented people.&lt;br&gt;
Feedback and suggestions are always welcome&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>learning</category>
    </item>
  </channel>
</rss>
