<?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: Syed Maaz Saeed </title>
    <description>The latest articles on DEV Community by Syed Maaz Saeed  (@syedmaazsaeed).</description>
    <link>https://dev.to/syedmaazsaeed</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%2F1160535%2F9a7b2fac-063b-47c3-814a-55a991310522.jpg</url>
      <title>DEV Community: Syed Maaz Saeed </title>
      <link>https://dev.to/syedmaazsaeed</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/syedmaazsaeed"/>
    <language>en</language>
    <item>
      <title>JWT explained in 4 minutes (With Visuals)</title>
      <dc:creator>Syed Maaz Saeed </dc:creator>
      <pubDate>Sun, 24 Mar 2024 15:47:41 +0000</pubDate>
      <link>https://dev.to/syedmaazsaeed/jwt-explained-in-4-minutes-with-visuals-2909</link>
      <guid>https://dev.to/syedmaazsaeed/jwt-explained-in-4-minutes-with-visuals-2909</guid>
      <description>&lt;h3&gt;
  
  
  **Introduction
&lt;/h3&gt;

&lt;p&gt;JWT authentication and session authentication are ways to authenticate users of your web app.&lt;br&gt;
In this article we will explain the details of JWT, its structure along with its pros and cons.&lt;br&gt;
JWT stands for JSON Web Token, and it is a commonly used stateless user authentication standard used to securely transmit information between client and server in a JSON format.&lt;br&gt;
A JWT is encoded and not encrypted by default.&lt;br&gt;
It is digitally signed using a secret key known only to the server.&lt;br&gt;
It can be encrypted, but for this article we will focus on signed non-encrypted tokens.&lt;/p&gt;

&lt;p&gt;**&lt;/p&gt;
&lt;h2&gt;
  
  
  Structure of JWT
&lt;/h2&gt;

&lt;p&gt;**&lt;br&gt;
A JSON Web Token consists of 3 parts separated by a period.&lt;br&gt;
The header, the payload, and the signature.&lt;br&gt;
Each section is base64 encoded&lt;/p&gt;

&lt;p&gt;**&lt;/p&gt;
&lt;h2&gt;
  
  
  Header
&lt;/h2&gt;

&lt;p&gt;**&lt;br&gt;
The header consists of token type, which is JWT, and the signing algorithm used, such as HMAC SHA256 or RSA.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{ 
  "typ": "JWT",    
  "alg": "HS256"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;**&lt;/p&gt;

&lt;h2&gt;
  
  
  Payload
&lt;/h2&gt;

&lt;p&gt;**&lt;/p&gt;

&lt;p&gt;The payload consists of the claims.&lt;br&gt;
Claims are statements about the user, and additional data.&lt;br&gt;
For example, we have the time the token was issued at.&lt;br&gt;
We also have its expiration time, because tokens should expire.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
"iss": "example_issuer",
"sub": "user_id123",
"exp": 1644768000,
"iat": 1644744000
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;**&lt;/p&gt;

&lt;h2&gt;
  
  
  Signature
&lt;/h2&gt;

&lt;p&gt;**&lt;/p&gt;

&lt;p&gt;The signature is most important part of a JWT.&lt;br&gt;
It is calculated using the header, the payload, and the secret, which are fed to the signing algorithm to use.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;signature = HMAC-SHA256(base64urlEncode(header) + "." + base64urlEncode(payload), secret_salt )

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;Steps&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;The steps involved in a typical JWT authorization flow are as follows:&lt;/p&gt;

&lt;p&gt;1- Authentication: The user signs in using username and password, or using for example Google or Facebook.&lt;br&gt;
The server verifies the provided credentials.&lt;/p&gt;

&lt;p&gt;2- Token Generation &amp;amp; sending token to client: The server will generate the JWT and send it to the client, which stores it for future use.&lt;/p&gt;

&lt;p&gt;3*&lt;em&gt;-Sending the Token to server&lt;/em&gt;*: When the client wants to access a protected resource on the server, it sends the JWT in the Authorization header of the HTTP request.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;axios.get(URL, {
    headers: {
        'Authorization': 'Bearer ' + token,
    },
})

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

&lt;/div&gt;



&lt;p&gt;4-Verifying the Token: The server receives the request and verifies the JWT by checking its signature using the secret key that was used to sign it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x1wtz6vfzqavwm94wkdz.png)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the JWT is valid, the server extracts the information contained in it and uses it to determine what actions the user is authorized to perform.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5- Authorizing the Request&lt;/strong&gt;: If the user is authorized to access the resource, the server returns the requested data. If the user is not authorized, the server returns an error message&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>authentication</category>
    </item>
    <item>
      <title>Setting Up a React Application</title>
      <dc:creator>Syed Maaz Saeed </dc:creator>
      <pubDate>Tue, 26 Dec 2023 17:08:10 +0000</pubDate>
      <link>https://dev.to/syedmaazsaeed/setting-up-a-react-application-57f3</link>
      <guid>https://dev.to/syedmaazsaeed/setting-up-a-react-application-57f3</guid>
      <description>&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Install Node.js&lt;/strong&gt;:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If you haven't already, download and install Node.js from Node.js website.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Create a React App&lt;/strong&gt;:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Open your terminal and run the following command to create a new React app using Create React App:&lt;br&gt;
npm create vite@latest   / npm init vite@latest my-vite-project&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Navigate to the Project Directory&lt;/strong&gt;:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Move into the newly created Vite project directory using the terminal:&lt;/p&gt;

&lt;p&gt;cd my-vite-project&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Install Dependencies&lt;/strong&gt;:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Inside the project directory, install the project dependencies using npm:&lt;/p&gt;

&lt;p&gt;npm install&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Run React App at localhost&lt;/strong&gt;:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Launch the development server provided by Vite to begin development:&lt;/p&gt;

&lt;p&gt;npm run dev&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Creating Pull Request ON Github</title>
      <dc:creator>Syed Maaz Saeed </dc:creator>
      <pubDate>Tue, 26 Dec 2023 17:01:22 +0000</pubDate>
      <link>https://dev.to/syedmaazsaeed/creating-pull-request-on-github-31bl</link>
      <guid>https://dev.to/syedmaazsaeed/creating-pull-request-on-github-31bl</guid>
      <description>&lt;ol&gt;
&lt;li&gt;Fork the Repository:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Visit the GitHub repository you want to contribute to.&lt;br&gt;
Click the "Fork" button in the top-right corner to create a personal copy of the repository.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Clone Your Fork:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Copy the URL of your forked repository.&lt;br&gt;
Open your terminal and run:&lt;br&gt;
git clone &lt;br&gt;
cd &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create a New Branch:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Establish a new branch for your changes:&lt;br&gt;
git checkout -b feature/my-contribution&lt;br&gt;
4.Make Changes:&lt;/p&gt;

&lt;p&gt;Implement the necessary changes to the code or documentation in your branch.&lt;br&gt;
5.Commit Changes:&lt;/p&gt;

&lt;p&gt;Stage your changes:&lt;br&gt;
git add .&lt;br&gt;
Commit the changes with a meaningful message:&lt;br&gt;
git commit -m "Added feature X"&lt;br&gt;
6.Push Changes:&lt;/p&gt;

&lt;p&gt;Push your changes to your forked repository:&lt;br&gt;
git push origin feature/my-contribution&lt;br&gt;
7.Create a Pull Request:&lt;/p&gt;

&lt;p&gt;Navigate to your forked repository on GitHub.&lt;br&gt;
Click on the "New Pull Request" button.&lt;br&gt;
Select the branch containing your changes.&lt;br&gt;
Provide a clear title and comment explaining your modifications.&lt;br&gt;
8.Review and Merge:&lt;/p&gt;

&lt;p&gt;The repository's owner or maintainers will assess your Pull Request.&lt;br&gt;
If everything checks out, they'll merge your changes into the main project.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Flat Map in JavaScript</title>
      <dc:creator>Syed Maaz Saeed </dc:creator>
      <pubDate>Sat, 30 Sep 2023 19:38:01 +0000</pubDate>
      <link>https://dev.to/syedmaazsaeed/flat-map-in-javascript-135d</link>
      <guid>https://dev.to/syedmaazsaeed/flat-map-in-javascript-135d</guid>
      <description>&lt;p&gt;Flat Map in javascript is a great technique which you can learn here. Flat map essentially conbines techniques of map and filter Array method into one. I will suggest you to use flatMap() over combination of filter() and map().&lt;/p&gt;

&lt;p&gt;FlatMap takes single pass and doesn’t produce intermediate array but filter ()and map() combination produces an intermediate array.&lt;/p&gt;

&lt;p&gt;// using filterAndMap&lt;br&gt;
console.time("filterAndMap")&lt;br&gt;
const numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];&lt;/p&gt;

&lt;p&gt;const squaredOddNumbers = numbers&lt;br&gt;
    .filter(num =&amp;gt; num % 2 !== 0)&lt;br&gt;
    .map(num =&amp;gt; num * num)&lt;/p&gt;

&lt;p&gt;console.log(squaredOddNumbers); // [1, 9, 25, 49, 81]&lt;br&gt;
console.timeEnd("filterAndMap")&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
