<?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: Wendy Tabitha</title>
    <description>The latest articles on DEV Community by Wendy Tabitha (@wendy_tabitha).</description>
    <link>https://dev.to/wendy_tabitha</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%2F1649808%2F52dc934b-7e00-475d-9120-e357d065fe11.png</url>
      <title>DEV Community: Wendy Tabitha</title>
      <link>https://dev.to/wendy_tabitha</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/wendy_tabitha"/>
    <language>en</language>
    <item>
      <title>Oops, Wrong Git Author — Here’s How I Fixed It</title>
      <dc:creator>Wendy Tabitha</dc:creator>
      <pubDate>Wed, 02 Jul 2025 13:25:22 +0000</pubDate>
      <link>https://dev.to/wendy_tabitha/oops-wrong-git-author-heres-how-i-fixed-it-5gjd</link>
      <guid>https://dev.to/wendy_tabitha/oops-wrong-git-author-heres-how-i-fixed-it-5gjd</guid>
      <description>&lt;h3&gt;
  
  
  Correcting Git Commit Author Information: A Beginner's Guide
&lt;/h3&gt;

&lt;p&gt;In the world of software development, it's not uncommon for developers to push commits with the wrong Git user identity. This can happen due to a variety of reasons, such as working on a shared machine, using multiple accounts, or forgetting to set the correct username and email before committing changes. While this might seem minor, it can lead to confusion in project history and affect collaboration with others. &lt;/p&gt;

&lt;p&gt;Before diving into how to delete or correct those errant commits, it's critical to understand the implications of rewriting Git history. When commits are deleted or altered in a shared repository, it can disrupt other team members who may have based their work on those commits. Therefore, managing Git history should be approached with caution.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Risks of Rewriting History
&lt;/h3&gt;

&lt;p&gt;Rewriting Git history can be risky, especially when it involves shared branches. If others have pulled the commits you're about to delete or alter, they will encounter issues when trying to push their changes. This is why it’s essential to either work on solo branches or coordinate with your team before making any drastic changes to shared branches.&lt;/p&gt;

&lt;p&gt;That said, here are some practical methods to delete or amend commits that were pushed with the wrong credentials:&lt;/p&gt;

&lt;h3&gt;
  
  
  Option 1: Deleting the Last Few Commits with &lt;code&gt;git reset&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;If you realize that you've pushed a couple of commits with the wrong credentials and they are the most recent ones, you can use the &lt;code&gt;git reset&lt;/code&gt; command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git reset &lt;span class="nt"&gt;--hard&lt;/span&gt; HEAD~N
git push &lt;span class="nt"&gt;--force&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this command, replace &lt;code&gt;N&lt;/code&gt; with the number of commits you want to remove. The &lt;code&gt;git reset --hard&lt;/code&gt; command will reset your branch to the state it was in &lt;code&gt;N&lt;/code&gt; commits ago, discarding all changes made in those commits. The &lt;code&gt;--force&lt;/code&gt; option is necessary to overwrite the remote branch with your local state.&lt;/p&gt;

&lt;h4&gt;
  
  
  When is it safe to use?
&lt;/h4&gt;

&lt;p&gt;It’s generally safe to use this method on branches that you’re working on alone. If you’re collaborating, make sure to communicate with your team beforehand.&lt;/p&gt;

&lt;h3&gt;
  
  
  Option 2: Interactively Rebasing with &lt;code&gt;git rebase -i&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;Another powerful way to amend commits is by using the interactive rebase feature of Git. With this method, you can selectively edit or drop commits.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git rebase &lt;span class="nt"&gt;-i&lt;/span&gt; HEAD~N
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command opens an editor where you can see the last &lt;code&gt;N&lt;/code&gt; commits. You can change "pick" to "edit" on the specific commit you want to amend. Save and exit the editor. &lt;/p&gt;

&lt;p&gt;If you've chosen a commit to edit, Git will pause the rebase process. Now, you can amend the author details with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git commit &lt;span class="nt"&gt;--amend&lt;/span&gt; &lt;span class="nt"&gt;--author&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"New Name &amp;lt;new.email@example.com&amp;gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After making your changes, continue the rebase with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git rebase &lt;span class="nt"&gt;--continue&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Best Practices to Consider
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Work on Solo Branches:&lt;/strong&gt; The safest approach is to make these changes on branches that only you are using.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Communication is Key:&lt;/strong&gt; If you need to rewrite history on a shared branch, make sure to let your team know so they can prepare for potential issues.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Use Cleanup Tools:&lt;/strong&gt; For comprehensive cleanup, especially on platforms like GitHub, consider using tools like BFG Repo-Cleaner, which can help remove sensitive data or incorrect credentials from your commit history.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  A Friendly Reminder
&lt;/h3&gt;

&lt;p&gt;Version control is a powerful tool that allows developers to maintain a history of changes and collaborate more effectively. However, with that power comes responsibility. Always be aware of the implications when altering Git history and approach such actions with caution. The next time you push a commit, just double-check that your credentials are correct—your future self will thank you!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Why You Should Use Poetry for Your Next Python Project</title>
      <dc:creator>Wendy Tabitha</dc:creator>
      <pubDate>Mon, 02 Jun 2025 07:29:35 +0000</pubDate>
      <link>https://dev.to/wendy_tabitha/why-you-should-use-poetry-for-your-next-python-project-2ii6</link>
      <guid>https://dev.to/wendy_tabitha/why-you-should-use-poetry-for-your-next-python-project-2ii6</guid>
      <description>&lt;h2&gt;
  
  
  Managing Python Projects with Poetry: A Beginner's Guide
&lt;/h2&gt;

&lt;p&gt;In the world of Python development, managing dependencies and project configurations can quickly become cumbersome. This is where &lt;strong&gt;Poetry&lt;/strong&gt; comes in. Poetry is a dependency management tool that simplifies the process of managing Python projects. It not only handles package dependencies but also creates virtual environments automatically and streamlines project packaging for distribution. In this article, we’ll explore how to install Poetry, create a project, manage dependencies, and even publish your package to PyPI.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Poetry and Why Use It?
&lt;/h2&gt;

&lt;p&gt;Poetry is a tool that helps you declare, manage, and install dependencies for your Python projects, while also providing a simple and intuitive way to manage your project's metadata. It is useful for developers because it simplifies the process of managing libraries and environments, allows for easy version control, and ultimately enhances productivity.&lt;/p&gt;

&lt;h2&gt;
  
  
  Installing Poetry
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Windows
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Open PowerShell or Command Prompt.&lt;/li&gt;
&lt;li&gt;Run the following command:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   &lt;span class="o"&gt;(&lt;/span&gt;Invoke-WebRequest &lt;span class="nt"&gt;-Uri&lt;/span&gt; https://install.python-poetry.org &lt;span class="nt"&gt;-UseBasicP&lt;/span&gt; | python -&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  macOS
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Open your terminal.&lt;/li&gt;
&lt;li&gt;Use the following command:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   curl &lt;span class="nt"&gt;-sSL&lt;/span&gt; https://install.python-poetry.org | python3 -
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Linux
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Open your terminal.&lt;/li&gt;
&lt;li&gt;Execute the command:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   curl &lt;span class="nt"&gt;-sSL&lt;/span&gt; https://install.python-poetry.org | python3 -
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Creating a New Python Project
&lt;/h2&gt;

&lt;p&gt;To create a new Python project using Poetry, navigate to your desired directory in the terminal, then run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;poetry new my_project
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This generates a new directory called &lt;code&gt;my_project&lt;/code&gt; with a basic structure, including &lt;code&gt;pyproject.toml&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Installing Python Dependencies
&lt;/h2&gt;

&lt;p&gt;To install dependencies listed in &lt;code&gt;pyproject.toml&lt;/code&gt;, run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd &lt;/span&gt;my_project
poetry &lt;span class="nb"&gt;install&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command also creates a virtual environment in which your dependencies will be installed.&lt;/p&gt;

&lt;h2&gt;
  
  
  Adding, Updating, and Removing Dependencies
&lt;/h2&gt;

&lt;p&gt;You can easily manage dependencies with the following commands:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Add a dependency&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;poetry add requests
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Update a dependency&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;poetry update requests
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Remove a dependency&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;poetry remove requests
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Automatic Virtual Environment Management
&lt;/h2&gt;

&lt;p&gt;One of the standout features of Poetry is its ability to manage virtual environments automatically. When you run any Poetry command, it checks if a virtual environment exists for the project. If not, it creates one, isolating your package and dependencies.&lt;/p&gt;

&lt;h2&gt;
  
  
  Using Poetry in Team Projects
&lt;/h2&gt;

&lt;p&gt;In team projects, it's crucial to keep track of dependencies across different development environments. Make sure to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use version control (like Git) to track changes in your &lt;code&gt;pyproject.toml&lt;/code&gt; and &lt;code&gt;poetry.lock&lt;/code&gt; files.&lt;/li&gt;
&lt;li&gt;Run &lt;code&gt;poetry install&lt;/code&gt; after cloning the repository to install dependencies specified.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Common Mistakes to Avoid
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Forgetting to activate the virtual environment: Always ensure that you’re in the virtual environment when running your code.&lt;/li&gt;
&lt;li&gt;Not committing your &lt;code&gt;poetry.lock&lt;/code&gt; file: This can lead to discrepancies in dependencies across different environments.&lt;/li&gt;
&lt;li&gt;Misconfiguring &lt;code&gt;pyproject.toml&lt;/code&gt;: Ensure that you properly list all required metadata and dependencies to avoid issues.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Poetry is an excellent tool for managing Python projects that significantly reduces complexity related to package management and environment setup. Whether you're a solo developer or part of a team, its features simplify the process of project initialization, dependency management, and package distribution. If you're looking for a way to streamline your Python project development, give Poetry a try!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Understanding JWTs: Secure Your APIs Like a Pro</title>
      <dc:creator>Wendy Tabitha</dc:creator>
      <pubDate>Tue, 20 May 2025 14:29:12 +0000</pubDate>
      <link>https://dev.to/wendy_tabitha/understanding-jwts-secure-your-apis-like-a-pro-igk</link>
      <guid>https://dev.to/wendy_tabitha/understanding-jwts-secure-your-apis-like-a-pro-igk</guid>
      <description>&lt;p&gt;&lt;strong&gt;Understanding JSON Web Tokens (JWTs) for Web Developers&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In the world of web development, security and efficient data exchange are two paramount concerns. One technology that has gained immense popularity for addressing these challenges is JSON Web Tokens (JWTs). This article aims to introduce you to JWTs, how they work, their common use cases, and provide practical code examples in Golang to help you integrate JWTs into your projects.&lt;/p&gt;

&lt;h3&gt;
  
  
  What are JSON Web Tokens?
&lt;/h3&gt;

&lt;p&gt;JSON Web Tokens, or JWTs, are an open standard (RFC 7519) for securely transmitting information between parties as a JSON object. This information can be verified and trusted because it is digitally signed. JWTs can be signed using a secret (with the HMAC algorithm) or a public/private key pair using RSA or ECDSA.&lt;/p&gt;

&lt;p&gt;A JWT is composed of three parts:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Header&lt;/strong&gt;: Contains metadata about the token, typically the type of token (JWT) and the signing algorithm.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Payload&lt;/strong&gt;: Contains the claims or the data being transmitted. This can include user information and other relevant data.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Signature&lt;/strong&gt;: Created by combining the header and payload, signing it using the chosen algorithm and a secret key.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This structure not only ensures data integrity but also facilitates the transmission of claims between parties.&lt;/p&gt;

&lt;h3&gt;
  
  
  How JWTs Work
&lt;/h3&gt;

&lt;p&gt;When a user logs in to a web application, the server generates a JWT that encodes the user's information and permissions. This token is then sent to the client, which stores it (usually in local storage). For every subsequent request, the client includes the JWT in the Authorization header. The server then verifies the token. If valid, the user is granted access to protected resources.&lt;/p&gt;

&lt;p&gt;Here's a simple illustration:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[Client] -- Log In --&amp;gt; [Server]
[Server] -- Sends JWT --&amp;gt; [Client]
[Client] -- Requests Protected Resource with JWT --&amp;gt; [Server]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Common Use Cases
&lt;/h3&gt;

&lt;p&gt;JWTs are particularly useful in situations such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Authentication&lt;/strong&gt;: After successful logins, JWTs allow users to access their session securely without repeatedly sending credentials.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Session Management&lt;/strong&gt;: JWTs can store session-related information to keep track of user state.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Single Sign-On (SSO)&lt;/strong&gt;: JWTs can enable seamless authentication across multiple applications.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Code Examples: Generating, Signing, and Verifying JWTs in Golang
&lt;/h3&gt;

&lt;p&gt;To work with JWTs in Golang, we can use the &lt;code&gt;github.com/dgrijalva/jwt-go&lt;/code&gt; library. Here’s a step-by-step guide on generating and verifying JWTs.&lt;/p&gt;

&lt;h4&gt;
  
  
  1. Generating a JWT
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="s"&gt;"fmt"&lt;/span&gt;
    &lt;span class="s"&gt;"github.com/dgrijalva/jwt-go"&lt;/span&gt;
    &lt;span class="s"&gt;"time"&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;GenerateJWT&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;secretKey&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;userID&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;claims&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;jwt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;MapClaims&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="s"&gt;"user_id"&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;userID&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s"&gt;"exp"&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;     &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Now&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Hour&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="m"&gt;72&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Unix&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="n"&gt;token&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;jwt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;NewWithClaims&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;jwt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;SigningMethodHS256&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;claims&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;token&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;SignedString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;secretKey&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;secretKey&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"your_secret_key"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;token&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;GenerateJWT&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;secretKey&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"12345"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="no"&gt;nil&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Error while generating JWT:"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Generated JWT:"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;token&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  2. Verifying a JWT
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;VerifyJWT&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;tokenString&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;secretKey&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;jwt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Token&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;jwt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Parse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;tokenString&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;func&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;token&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;jwt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Token&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;interface&lt;/span&gt;&lt;span class="p"&gt;{},&lt;/span&gt; &lt;span class="kt"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ok&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;token&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Method&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;jwt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;SigningMethodHMAC&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;ok&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="no"&gt;nil&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Errorf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"unexpected signing method: %v"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;token&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Header&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"alg"&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;secretKey&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;nil&lt;/span&gt;
    &lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Best Practices and Security Concerns
&lt;/h3&gt;

&lt;p&gt;When using JWTs, it’s essential to consider the following best practices:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Use HTTPS&lt;/strong&gt;: Always transmit JWTs over secure connections to prevent interception.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Expiration Time&lt;/strong&gt;: Set appropriate expiration times for tokens to mitigate risks from stolen tokens.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Revocation Strategies&lt;/strong&gt;: Have a plan for revoking tokens if a user's access should be terminated.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Avoid Sensitive Data&lt;/strong&gt;: Never store sensitive information in the payload, as anyone with access to the token can read it.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;JSON Web Tokens are a powerful tool for managing authentication and session management in web applications. By understanding their structure, functionality, and implementation techniques in Golang, you’ll be well-equipped to incorporate JWTs into your projects while adhering to best security practices. As you gain experience, you’ll find JWTs to be invaluable in delivering secure, scalable, and efficient web applications.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>The JavaScript Event Loop</title>
      <dc:creator>Wendy Tabitha</dc:creator>
      <pubDate>Thu, 13 Feb 2025 13:03:28 +0000</pubDate>
      <link>https://dev.to/wendy_tabitha/the-javascript-event-loop-51kn</link>
      <guid>https://dev.to/wendy_tabitha/the-javascript-event-loop-51kn</guid>
      <description>&lt;p&gt;Have you ever wondered how JavaScript handles multiple tasks at once, even though it’s single-threaded? The secret lies in the event loop, one of the most fundamental yet misunderstood concepts in JavaScript. For many developers, especially those new to asynchronous programming, understanding the event loop can feel like unraveling a mystery.&lt;/p&gt;

&lt;p&gt;In this article, we’ll demystify the event loop by exploring its components, how it works behind the scenes, and why it’s crucial for writing efficient, responsive code. Whether you’re debugging asynchronous functions, working with promises, or simply trying to understand how JavaScript manages tasks, this guide will equip you with the knowledge you need to navigate the event loop like a pro.&lt;/p&gt;

&lt;h2&gt;
  
  
  Understanding the Event Loop in JavaScript
&lt;/h2&gt;

&lt;p&gt;JavaScript is a powerful and widely-used programming language, particularly in web development. However, for many budding developers, the intricacies of asynchronous programming can be baffling. One of the core concepts in JavaScript that helps manage asynchronous operations is the event loop. Let’s unpack what it is, how it works, and why it’s essential for software developers.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is the Event Loop?
&lt;/h3&gt;

&lt;p&gt;At its core, the event loop is a mechanism that allows JavaScript to perform non-blocking operations, even though it’s single-threaded. This means that while one operation is running, JavaScript can still handle other tasks. It achieves this through a combination of the call stack, the Web APIs (or other environments), and the event queue.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Call Stack
&lt;/h3&gt;

&lt;p&gt;Whenever you call a function in JavaScript, it gets pushed onto the call stack. When the function completes, it is popped off. If a function calls another function, the latter gets added to the stack, leading to a last-in-first-out scenario. Here’s a simple example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;first&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;First&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;second&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Second&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nf"&gt;first&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;second&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, calling &lt;code&gt;second()&lt;/code&gt; adds it to the stack. After logging "Second", it calls &lt;code&gt;first()&lt;/code&gt;, which is also pushed onto the stack until it completes, resulting in:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Second
First
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Web APIs and the Event Queue
&lt;/h3&gt;

&lt;p&gt;JavaScript engines interact with the browser's Web APIs to manage asynchronous tasks like timers, network requests, or DOM events. When an asynchronous task completes, it doesn’t get executed immediately. Instead, a callback function is put in the event queue, waiting for the call stack to be empty before it can be executed.&lt;/p&gt;

&lt;p&gt;Let’s illustrate with a timer example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Start&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nf"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Timeout&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;End&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here’s what happens step-by-step:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;"Start" is logged immediately.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;setTimeout&lt;/code&gt; function schedules the callback to execute after 1 second, and the timer starts.&lt;/li&gt;
&lt;li&gt;"End" is logged immediately after.&lt;/li&gt;
&lt;li&gt;After the timer completes, the callback is added to the event queue.&lt;/li&gt;
&lt;li&gt;Once the call stack is clear, or in this case, after the "End" log, "Timeout" is printed.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Why is the Event Loop Important?
&lt;/h3&gt;

&lt;p&gt;Understanding the event loop is essential for software developers, especially when dealing with asynchronous functions, promises, or APIs. It ensures that applications remain responsive while waiting for multiple operations to complete.&lt;/p&gt;

&lt;p&gt;For example, when making an API request, the UI doesn’t freeze while waiting for the server to respond — JavaScript handles it in the background. Here’s a quick snippet using Fetch:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Fetching data...&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://jsonplaceholder.typicode.com/posts&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Error:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Fetch initiated&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this code, the fetch operation runs asynchronously. Even as the fetch request is being processed, "Fetch initiated" will be logged immediately, demonstrating the power of the event loop.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;The event loop is a fundamental concept in JavaScript that enables asynchronous programming. By allowing JavaScript to perform multiple tasks simultaneously despite being single-threaded, it plays a critical role in maintaining a responsive user experience. Understanding it will enhance your skills as a developer and empower you to write more efficient, effective code. Now go ahead and embrace the event loop!&lt;/p&gt;

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