<?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: Saurabh Sharma</title>
    <description>The latest articles on DEV Community by Saurabh Sharma (@saurabh2k1).</description>
    <link>https://dev.to/saurabh2k1</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%2F679181%2F3816b0f5-4969-48ba-a0bf-8c17f37acfb9.png</url>
      <title>DEV Community: Saurabh Sharma</title>
      <link>https://dev.to/saurabh2k1</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/saurabh2k1"/>
    <language>en</language>
    <item>
      <title>Authentication and Authorization Microservice with Node.js, Express, PostgreSQL, and 2-Factor : Part 1</title>
      <dc:creator>Saurabh Sharma</dc:creator>
      <pubDate>Wed, 26 Mar 2025 07:15:01 +0000</pubDate>
      <link>https://dev.to/saurabh2k1/authentication-and-authorization-microservice-with-nodejs-express-postgresql-and-2-factor--10ic</link>
      <guid>https://dev.to/saurabh2k1/authentication-and-authorization-microservice-with-nodejs-express-postgresql-and-2-factor--10ic</guid>
      <description>&lt;p&gt;In today’s digital landscape, securing user authentication is more critical than ever. Whether you're developing a SaaS platform, an enterprise application, or a multi-tenant system, a robust authentication and authorization microservice can help centralize user management and enforce security best practices. In this blog post, we will walk through the complete development of an authentication and authorization microservice using Node.js, Express, and PostgreSQL, incorporating JWT-based authentication, role-based access control (RBAC), and Two-Factor Authentication (2FA) using TOTP (Time-Based One-Time Passwords). We will also ensure industry-grade security practices, including password hashing, input validation, and secure token management. By the end of this guide, you'll have a production-ready microservice that can be integrated with multiple applications, serving as a reliable identity provider. Let’s get started! 🚀&lt;/p&gt;

&lt;p&gt;It is part of series:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Part 1&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Part 2&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Part 3&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Authentication &amp;amp; Authorization:
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Mechanisms&lt;/strong&gt;: Username/password, TOTP.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Services&lt;/strong&gt;: User registration, authenticator registration, login, token issuance (JWT or OAuth2), and role-based access control.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Super Admin&lt;/strong&gt;: One dedicated user with elevated privileges.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Deployment&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Containerization&lt;/strong&gt;: Docker support for easier deployment and orchestration (e.g., Kubernetes).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Security&lt;/strong&gt;:&lt;br&gt;
Industry best practices, such as secure password storage&lt;br&gt;
Initialize Project&lt;/p&gt;
&lt;h3&gt;
  
  
  Let's start
&lt;/h3&gt;
&lt;h4&gt;
  
  
  1. Create directory &amp;amp; initiate npm
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;mkdir &lt;/span&gt;auth-service
&lt;span class="nb"&gt;cd &lt;/span&gt;auth-service
npm init &lt;span class="nt"&gt;-y&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h5&gt;
  
  
  Install typescript and other development dependency
&lt;/h5&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install &lt;/span&gt;typescript ts-node @types/node &lt;span class="nt"&gt;--save-dev&lt;/span&gt;
tsc &lt;span class="nt"&gt;--init&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h5&gt;
  
  
  Install express framework and database ORM (TypeORM) &amp;amp; pg
&lt;/h5&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install &lt;/span&gt;express typeorm pg dotenv
npm &lt;span class="nb"&gt;install&lt;/span&gt; @types/express &lt;span class="nt"&gt;--save-dev&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h5&gt;
  
  
  To get it work, open &lt;code&gt;tsconfig.json&lt;/code&gt; and add following settings in &lt;em&gt;compilerOptions&lt;/em&gt;
&lt;/h5&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="nl"&gt;"experimentalDecorators"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="nl"&gt;"emitDecoratorMetadata"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="nl"&gt;"strictPropertyInitialization"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  2. Install Postgres &amp;amp; pgAdmin using docker-compose
&lt;/h4&gt;

&lt;p&gt;create file    &lt;code&gt;docker-compose.yml&lt;/code&gt; in root and copy the following content&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;version&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;3.8"&lt;/span&gt;
&lt;span class="na"&gt;services&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;db&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;image&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;postgres&lt;/span&gt;
    &lt;span class="na"&gt;container_name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;local_pgdb&lt;/span&gt;
    &lt;span class="na"&gt;restart&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;always&lt;/span&gt;
    &lt;span class="na"&gt;ports&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;5432:5432"&lt;/span&gt;
    &lt;span class="na"&gt;environment&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;POSTGRES_USER=${DB_USER}&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;POSTGRES_PASSWORD=${DB_PASSWORD}&lt;/span&gt;
    &lt;span class="na"&gt;volumes&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;local_pgdata:/var/lib/postgresql/data&lt;/span&gt;
  &lt;span class="na"&gt;pgadmin&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;image&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;dpage/pgadmin4&lt;/span&gt;
    &lt;span class="na"&gt;container_name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;pgadmin4_container&lt;/span&gt;
    &lt;span class="na"&gt;restart&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;always&lt;/span&gt;
    &lt;span class="na"&gt;ports&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;8888:80"&lt;/span&gt;
    &lt;span class="na"&gt;environment&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;PGADMIN_DEFAULT_EMAIL=${PGADMIN_DEFAULT_EMAIL}&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;PGADMIN_DEFAULT_PASSWORD=${PGADMIN_DEFAULT_PASSWORD}&lt;/span&gt;
    &lt;span class="na"&gt;volumes&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;pgadmin-data:/var/lib/pgadmin&lt;/span&gt;

&lt;span class="na"&gt;volumes&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;local_pgdata&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;pgadmin-data&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Create .env file in root with your credentials (Don't use the given details)&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ini"&gt;&lt;code&gt;&lt;span class="py"&gt;DB_HOST&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;localhost&lt;/span&gt;
&lt;span class="py"&gt;DB_PORT&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;5432&lt;/span&gt;

&lt;span class="py"&gt;DB_USERNAME&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;postgres&lt;/span&gt;
&lt;span class="py"&gt;DB_PASSWORD&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;postgres&lt;/span&gt;

&lt;span class="py"&gt;PGADMIN_DEFAULT_EMAIL&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;pgadmin@postgres.com&lt;/span&gt;
&lt;span class="py"&gt;PGADMIN_DEFAULT_PASSWORD&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;pgadmin&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h5&gt;
  
  
  Run the docker
&lt;/h5&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker-compose up &lt;span class="nt"&gt;-d&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h5&gt;
  
  
  Check the containers status
&lt;/h5&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker ps
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffilemc4emugr531qmytl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffilemc4emugr531qmytl.png" alt="docker ps output" width="800" height="87"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;you can access the pgAdmin using url &lt;a href="http://localhost:8888%C2%A0" rel="noopener noreferrer"&gt;http://localhost:8888 &lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;login using your credentials and create server connection &lt;/li&gt;
&lt;li&gt;host will be container name(eg.local_pgdb)  of Postgres container&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  3. ORM Configuration
&lt;/h4&gt;

&lt;p&gt;create &lt;code&gt;data-source.ts&lt;/code&gt; file in &lt;code&gt;src&lt;/code&gt; folder with following code&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;DataSource&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;typeorm&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nx"&gt;dotenv&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;dotenv&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;dotenv&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;config&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;AppDataSource&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;DataSource&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;postgres&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
  &lt;span class="na"&gt;host&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;localhost&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;port&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;5432&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;username&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;DB_USERNAME&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;postgres&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;password&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;DB_PASSWORD&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;postgres&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;database&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;DB_DATABASE&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;postgres&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;synchronize&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;    &lt;span class="c1"&gt;// make false for production&lt;/span&gt;
  &lt;span class="na"&gt;logging&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;entities&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;src/entity/**/*.ts&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="na"&gt;migrations&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;src/migration/**/*.ts&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="na"&gt;subscribers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;src/subscriber/**/*.ts&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="nx"&gt;AppDataSource&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;initialize&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="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;Data Source has been initialized!&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="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;err&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;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 during Data Source initialization:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;err&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;h5&gt;
  
  
  Create following folder structure in src folder
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;src/entity&lt;/li&gt;
&lt;li&gt;src/migration&lt;/li&gt;
&lt;li&gt;src/subscriber&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  3.1 Create Database Schema
&lt;/h4&gt;
&lt;h5&gt;
  
  
  Create a &lt;code&gt;Userentity&lt;/code&gt; in &lt;code&gt;src/entity/User.ts&lt;/code&gt;:
&lt;/h5&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Entity&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;PrimaryGeneratedColumn&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Column&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;CreateDateColumn&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;typeorm&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="nd"&gt;Entity&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;User&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;PrimaryGeneratedColumn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;uuid&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Column&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;unique&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt;
  &lt;span class="nx"&gt;username&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Column&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
  &lt;span class="nx"&gt;passwordHash&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Column&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;default&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;user&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt;
  &lt;span class="nx"&gt;role&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Column&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;nullable&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt;
  &lt;span class="nx"&gt;totpSecret&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;CreateDateColumn&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
  &lt;span class="nx"&gt;createdAt&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Date&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;h5&gt;
  
  
  Create migration file &lt;code&gt;CreateUserTable&lt;/code&gt; in &lt;code&gt;src/migration&lt;/code&gt;
&lt;/h5&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx typeorm-ts-node-commonjs &lt;span class="nt"&gt;-d&lt;/span&gt; ./src/data-source.ts migration:generate ./src/migration/CreateUserTable
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h5&gt;
  
  
  Run the migration using following command
&lt;/h5&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx typeorm-ts-node-commonjs &lt;span class="nt"&gt;-d&lt;/span&gt; src/data-source.ts migration:run
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  Install other libraries
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install &lt;/span&gt;bcrypt speakeasy qrcode jsonwebtoken express-validator
npm &lt;span class="nb"&gt;install&lt;/span&gt; @types/bcrypt @types/speakeasy  @types/qrcode @types/jsonwebtoken
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  4. Startup file
&lt;/h4&gt;

&lt;p&gt;Create &lt;code&gt;index.ts&lt;/code&gt; file in &lt;code&gt;src&lt;/code&gt; folder with following initial code:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;express&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;express&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;AppDataSource&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./data-source&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;express&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/health&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="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&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;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Auth Microservice is running&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="nx"&gt;AppDataSource&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;initialize&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="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;Data Source has been initialized!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;listen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3000&lt;/span&gt;&lt;span class="p"&gt;,&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="s1"&gt;Auth Microservice is running on port 3000&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="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;err&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;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 during Data Source initialization:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;err&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;h5&gt;
  
  
  Create start script in &lt;code&gt;package.json&lt;/code&gt; as below:
&lt;/h5&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="nl"&gt;"scripts"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"test"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"echo &lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;Error: no test specified&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt; &amp;amp;&amp;amp; exit 1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; 
    &lt;/span&gt;&lt;span class="nl"&gt;"start"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"ts-node ./src/index.ts"&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;run the application using &lt;code&gt;npm run start&lt;/code&gt;&lt;br&gt;
You can access the code from repository &lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fassets.dev.to%2Fassets%2Fgithub-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/saurabh2k1" rel="noopener noreferrer"&gt;
        saurabh2k1
      &lt;/a&gt; / &lt;a href="https://github.com/saurabh2k1/auth-service" rel="noopener noreferrer"&gt;
        auth-service
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      Authentication &amp;amp; Authorization Microservice 
    &lt;/h3&gt;
  &lt;/div&gt;
&lt;/div&gt;






&lt;p&gt;Part 2 is coming...&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>node</category>
      <category>postgres</category>
    </item>
    <item>
      <title>From Fairy Tales to Future Tech: A Letter to My Loved Ones</title>
      <dc:creator>Saurabh Sharma</dc:creator>
      <pubDate>Tue, 18 Mar 2025 05:41:49 +0000</pubDate>
      <link>https://dev.to/saurabh2k1/from-fairy-tales-to-future-tech-a-letter-to-my-loved-ones-46dm</link>
      <guid>https://dev.to/saurabh2k1/from-fairy-tales-to-future-tech-a-letter-to-my-loved-ones-46dm</guid>
      <description>&lt;p&gt;&lt;em&gt;This is a submission for the &lt;a href="https://future.forem.com/challenges/writing-2025-02-26"&gt;Future Writing Challenge&lt;/a&gt;: How Technology Is Changing Things.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Dear Family and Friends,&lt;/p&gt;

&lt;p&gt;I hope you’re all doing well! I wanted to share some thoughts about how technology is gently reshaping our everyday world—a journey that touches every part of our lives.&lt;/p&gt;

&lt;p&gt;Imagine technology as a friendly, magical helper. Just like a colorful toy robot that sings and dances, it makes many things easier and more fun. For example, it’s like having a magic picture book that shows us faraway lands, helps us learn new things, and even keeps us connected with loved ones no matter where we are. Even a five-year-old can understand that it’s a bit like having a magic wand that sprinkles excitement and ease into our daily routine!&lt;/p&gt;

&lt;p&gt;But the magic isn’t just for little wonders—it’s also creating big ripple effects in our culture. Our schools are turning digital, letting kids learn from teachers and friends across the globe. In our work lives, technology means that many of us can connect from anywhere, making collaboration easier and more creative. Even how we meet new people, celebrate milestones, or share family traditions is evolving with social media and smart devices.&lt;/p&gt;

&lt;p&gt;As we step into this future, let’s see these changes as opportunities to grow closer and create new ways of learning, working, and sharing love. I write this to all of you—across every generation—so we can embrace these shifts together, with curiosity and warmth.&lt;/p&gt;

&lt;p&gt;With love and excitement for the future,&lt;/p&gt;

&lt;p&gt;Saurabh Sharma&lt;/p&gt;

&lt;h3&gt;
  
  
  Additional Prize Categories
&lt;/h3&gt;

&lt;p&gt;Explain Like I'm Five, &lt;br&gt;
Ripple Effects&lt;/p&gt;

</description>
      <category>futurechallenge</category>
      <category>futuretech</category>
      <category>ai</category>
      <category>discuss</category>
    </item>
    <item>
      <title>Using React-admin Dashboard for Application Management</title>
      <dc:creator>Saurabh Sharma</dc:creator>
      <pubDate>Tue, 25 Feb 2025 10:57:04 +0000</pubDate>
      <link>https://dev.to/saurabh2k1/using-react-admin-dashboard-for-application-management-3eb2</link>
      <guid>https://dev.to/saurabh2k1/using-react-admin-dashboard-for-application-management-3eb2</guid>
      <description>&lt;p&gt;Building an application can feel overwhelming, especially when it comes to managing its data and user interface. &lt;strong&gt;Using a &lt;a href="https://marmelab.com/react-admin/" rel="noopener noreferrer"&gt;React-admin&lt;/a&gt; dashboard streamlines this process by providing a robust and customizable framework for creating your admin panel quickly and efficiently.&lt;/strong&gt; The integration of React-admin not only enhances the user experience but also simplifies the development process.&lt;/p&gt;

&lt;p&gt;In my experience, the flexibility of React-admin allows me to tailor the dashboard to the specific needs of my application. This means I can focus on what matters most—developing features that provide real value to my users. With its rich set of tools and components, React-admin aids in reducing the amount of boilerplate code, enabling me to implement functionalities faster.&lt;/p&gt;

&lt;p&gt;Ultimately, adopting React-admin for your application empowers you to maintain control over data management while delivering a user-friendly interface. The immediate benefits of quicker setup times and enhanced customization make it an appealing choice for developers seeking efficiency and functionality in their projects.&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting Started with React-Admin
&lt;/h2&gt;

&lt;p&gt;I will outline the essential steps for setting up React-Admin. This section covers the installation and setup process, basic configuration, and the architecture of React-Admin.&lt;/p&gt;

&lt;h3&gt;
  
  
  Installation and Setup
&lt;/h3&gt;

&lt;p&gt;To begin using React-Admin, I need to ensure that Node.js and npm are installed on my machine. I can install React-Admin in a new or existing project using npm or yarn. Here’s the command for installation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install &lt;/span&gt;react-admin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After installation, I can start creating my Admin component. This involves importing React-Admin components and setting up the data provider. For a quick start, I often use the REST data provider, which can be installed with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install &lt;/span&gt;ra-data-json-server
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This provider allows me to connect to a JSON server easily and is perfect for rapid development.&lt;/p&gt;

&lt;h3&gt;
  
  
  Basic Configuration
&lt;/h3&gt;

&lt;p&gt;With React-Admin set up, I can create the basic configuration for my dashboard. I typically start by defining a simple data provider and passing it to the &lt;code&gt;&amp;lt;Admin&amp;gt;&lt;/code&gt; component. Here’s an example structure:&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="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Admin&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Resource&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react-admin&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;jsonServerProvider&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;ra-data-json-server&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;dataProvider&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;jsonServerProvider&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;http://jsonplaceholder.typicode.com&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt; &lt;span class="o"&gt;=&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Admin&lt;/span&gt; &lt;span class="nx"&gt;dataProvider&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;dataProvider&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Resource&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;posts&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Resource&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;comments&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/Admin&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This setup enables me to start working with resources right away. I can customize the resources by defining create, edit, and list views based on my needs.&lt;/p&gt;

&lt;h3&gt;
  
  
  Understanding the React-Admin Architecture
&lt;/h3&gt;

&lt;p&gt;React-Admin is built around a set of core principles that make it a powerful tool for creating admin interfaces. At its core, it separates concerns by using components for different functionalities.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key components include:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Admin&lt;/strong&gt;: The main container for my application.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Resource&lt;/strong&gt;: Represents the data entity I manage, such as &lt;code&gt;posts&lt;/code&gt; or &lt;code&gt;users&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;React-Admin operates on a data provider pattern, allowing me to switch data sources easily. This flexibility enables me to integrate with REST APIs, GraphQL, and other sources without changing the frontend significantly. Each resource can be configured with custom views, providing complete control over the presentation and functionality.&lt;/p&gt;

&lt;h2&gt;
  
  
  Core Components of React-Admin
&lt;/h2&gt;

&lt;p&gt;React-Admin consists of essential components that work together to create a powerful and flexible dashboard. Understanding these components is crucial for developing applications effectively. Below, I provide an overview of the core components that drive React-Admin's functionality.&lt;/p&gt;

&lt;h3&gt;
  
  
  DataProvider
&lt;/h3&gt;

&lt;p&gt;The &lt;em&gt;DataProvider&lt;/em&gt; is a critical component in React-Admin. It acts as an interface between the user interface and the data layer. This abstraction allows me to interact with various data sources, including REST, GraphQL, or any custom API.&lt;/p&gt;

&lt;p&gt;The DataProvider handles CRUD operations seamlessly. This means I can retrieve, create, update, or delete resources. Additionally, I can easily customize it to fit my backend requirements, allowing for scalability and versatility.&lt;/p&gt;

&lt;p&gt;When implementing a DataProvider, I define methods like &lt;code&gt;getList&lt;/code&gt;, &lt;code&gt;getOne&lt;/code&gt;, &lt;code&gt;create&lt;/code&gt;, and &lt;code&gt;update&lt;/code&gt;. These methods return Promises, which integrate smoothly with React-Admin's asynchronous paradigm. Setting up the DataProvider efficiently ensures a robust application capable of meeting user demands.&lt;/p&gt;

&lt;h3&gt;
  
  
  AuthenticationProvider
&lt;/h3&gt;

&lt;p&gt;An &lt;em&gt;AuthenticationProvider&lt;/em&gt; is vital for securing my application. It manages user authentication and authorization within the dashboard, ensuring that only authorized users can access certain resources.&lt;/p&gt;

&lt;p&gt;This provider often integrates with OAuth, JWT tokens, or any authentication setup I choose. I define methods such as &lt;code&gt;login&lt;/code&gt;, &lt;code&gt;logout&lt;/code&gt;, and &lt;code&gt;checkAuth&lt;/code&gt;. This way, I can manage user sessions effectively and enhance security.&lt;/p&gt;

&lt;p&gt;When a user attempts to log in, the AuthenticationProvider verifies credentials and responds appropriately. Proper implementation of this component is essential for a secure and reliable application, protecting sensitive data and resources.&lt;/p&gt;

&lt;h3&gt;
  
  
  Admin Component
&lt;/h3&gt;

&lt;p&gt;The &lt;em&gt;Admin Component&lt;/em&gt; serves as the central component of my React-Admin application. It brings together various parts of the application, rendering the layout and handling routing. This component is where I define my dataProvider and authenticationProvider.&lt;/p&gt;

&lt;p&gt;The Admin Component is reusable and easy to configure. I can customize the dashboard by defining the title, layout, and other props. Additionally, it acts as a high-level router, managing different resources.&lt;/p&gt;

&lt;p&gt;Using the Admin Component, I can create a cohesive and intuitive user interface. It helps maintain structure while ensuring flexibility for UI modifications as my project evolves.&lt;/p&gt;

&lt;h3&gt;
  
  
  Resource Component
&lt;/h3&gt;

&lt;p&gt;The &lt;em&gt;Resource Component&lt;/em&gt; is essential for defining data entities within the application. Each resource corresponds to a data entity I want to manage, such as users, products, or orders. This component allows me to specify how each resource will be displayed and manipulated.&lt;/p&gt;

&lt;p&gt;Within the Resource Component, I can define views for listing, editing, and creating records. By using built-in components like &lt;code&gt;&amp;lt;List&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;Edit&amp;gt;&lt;/code&gt;, or &lt;code&gt;&amp;lt;Create&amp;gt;&lt;/code&gt;, I ensure that my application adheres to a consistent UI and functionality.&lt;/p&gt;

&lt;p&gt;Each resource can be further customized with specific fields and filters, accommodating various data requirements. The Resource Component simplifies the management of multiple data entities while preserving clarity in my application's structure.&lt;/p&gt;

&lt;h2&gt;
  
  
  Building a Dashboard
&lt;/h2&gt;

&lt;p&gt;Creating a dashboard in React-admin involves configuring various components and potentially developing custom widgets that enhance functionality. Here’s how I approach these essential aspects.&lt;/p&gt;

&lt;h3&gt;
  
  
  Dashboard Configuration
&lt;/h3&gt;

&lt;p&gt;Dashboard configuration in React-admin allows for flexibility and scalability. I start by defining my data sources, typically through a REST or GraphQL API. This involves setting up resource components that detail how data is accessed and displayed.&lt;/p&gt;

&lt;p&gt;Next, I customize the layout using built-in layout components like &lt;code&gt;&amp;lt;Card&amp;gt;&lt;/code&gt; or &lt;code&gt;&amp;lt;Grid&amp;gt;&lt;/code&gt;, which let me organize information effectively. Utilizing the &lt;code&gt;Dashboard&lt;/code&gt; component, I can specify widgets that showcase key metrics, using &lt;code&gt;&amp;lt;SimpleList&amp;gt;&lt;/code&gt; or &lt;code&gt;&amp;lt;Stat&amp;gt;&lt;/code&gt; components for simplicity.&lt;/p&gt;

&lt;p&gt;I also make use of styles and themes to align the dashboard’s appearance with branding. It’s crucial to leverage the permissions feature to control user access, ensuring that sensitive information remains protected.&lt;/p&gt;

&lt;h3&gt;
  
  
  Custom Widgets
&lt;/h3&gt;

&lt;p&gt;Custom widgets enhance user interaction and data presentation. I create these by building new components that integrate seamlessly with existing React-admin tools.&lt;/p&gt;

&lt;p&gt;To get started, I define the component structure using React hooks, which allow for functional and responsive interfaces. I ensure that each widget adheres to the overall dashboard design.&lt;/p&gt;

&lt;p&gt;For instance, I might develop a chart widget using libraries like &lt;code&gt;recharts&lt;/code&gt; or &lt;code&gt;chart.js&lt;/code&gt;. This helps visualize data trends effectively. Additionally, I implement tools for filtering and sorting data, making the dashboard more user-friendly.&lt;/p&gt;

&lt;p&gt;By adding interactivity through state management, I can provide real-time updates, significantly improving user engagement and decision-making.&lt;/p&gt;

&lt;h2&gt;
  
  
  Data Management
&lt;/h2&gt;

&lt;p&gt;Effective data management is crucial for any application utilizing React-admin. This section covers how to perform CRUD operations seamlessly and implement robust data validation and error handling.&lt;/p&gt;

&lt;h3&gt;
  
  
  CRUD Operations
&lt;/h3&gt;

&lt;p&gt;React-admin simplifies CRUD (Create, Read, Update, Delete) operations through its intuitive interface. Utilizing the built-in data provider, I can easily connect to various backends, including REST and GraphQL APIs.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Create&lt;/strong&gt;: I use forms that automatically handle inputs. The &lt;code&gt;&amp;lt;Create&amp;gt;&lt;/code&gt; component generates structured forms for data entry.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Read&lt;/strong&gt;: Fetching data is straightforward with &lt;code&gt;&amp;lt;List&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;Show&amp;gt;&lt;/code&gt; components. I can customize these components to display information clearly.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Update&lt;/strong&gt;: With the &lt;code&gt;&amp;lt;Edit&amp;gt;&lt;/code&gt; component, I can modify existing entries easily. It also supports form validation to ensure data integrity.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Delete&lt;/strong&gt;: The &lt;code&gt;&amp;lt;DeleteButton&amp;gt;&lt;/code&gt; component allows me to remove entries efficiently. Confirmation dialogues help prevent accidental deletions.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Data Validation and Error Handling
&lt;/h3&gt;

&lt;p&gt;Data validation is essential to maintain data quality. React-admin offers validation rules that can be applied to forms.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Client-side Validation&lt;/strong&gt;: I can define custom validation logic using functions. This ensures that invalid data does not reach the server.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Server-side Validation&lt;/strong&gt;: Implementing API-level validation enhances reliability. I handle API responses to identify and manage errors.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Error handling can be incorporated using notification systems. For instance, I use the &lt;code&gt;&amp;lt;Notification&amp;gt;&lt;/code&gt; component to inform users of successful or failed operations. &lt;/p&gt;

&lt;p&gt;Implementing effective data validation and error handling improves user experience and application reliability.&lt;/p&gt;

&lt;h2&gt;
  
  
  Authentication and Authorization
&lt;/h2&gt;

&lt;p&gt;I prioritize securing user access through effective authentication and authorization strategies. These protocols ensure that only validated users can access sensitive areas of the application.&lt;/p&gt;

&lt;h3&gt;
  
  
  User Authentication Workflow
&lt;/h3&gt;

&lt;p&gt;In my applications, I implement a user authentication workflow that typically involves several steps. First, users provide their credentials, usually a username and password. &lt;/p&gt;

&lt;p&gt;Next, I verify these credentials against a backend service. Upon successful verification, the system generates a token, often a JSON Web Token (JWT), that the user receives. This token serves as proof of their identity in subsequent requests. &lt;/p&gt;

&lt;p&gt;To enhance security, I also encourage the use of multi-factor authentication (MFA). This additional layer can include SMS codes or authentication apps, significantly reducing unauthorized access.&lt;/p&gt;

&lt;h3&gt;
  
  
  Access Control and Permissions
&lt;/h3&gt;

&lt;p&gt;Access control defines what authenticated users can do within the application. I establish roles for different user types, such as admin, editor, or viewer.&lt;/p&gt;

&lt;p&gt;Through role-based access control (RBAC), I map specific permissions to these roles. For instance, only admins can manage user accounts and settings, while editors can create and edit content. &lt;/p&gt;

&lt;p&gt;Implementing this structure involves updating the user interface to display options based on their roles. I typically use conditional rendering in React to achieve this dynamic visibility. &lt;/p&gt;

&lt;p&gt;This ensures that unauthorized actions are prevented, maintaining data integrity and security across the platform.&lt;/p&gt;

&lt;h2&gt;
  
  
  Deploying React-Admin Applications
&lt;/h2&gt;

&lt;p&gt;Effective deployment of a React-Admin application requires attention to the build process and appropriate environment configuration. I will cover the essential steps to ensure a smooth deployment experience.&lt;/p&gt;

&lt;h3&gt;
  
  
  Build and Deployment Process
&lt;/h3&gt;

&lt;p&gt;To deploy a React-Admin application, I start by creating a production build. In the terminal, I run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm run build
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command generates an optimized version of the app in the &lt;code&gt;build&lt;/code&gt; directory.&lt;/p&gt;

&lt;p&gt;Next, I need to decide on a deployment platform. Popular choices include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Netlify&lt;/strong&gt;: Great for static sites; integrates well with Git.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Vercel&lt;/strong&gt;: Excellent for both static and dynamic applications.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;AWS S3&lt;/strong&gt;: Suitable for hosting static files with scalability.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;After choosing a platform, I follow its deployment instructions. I typically upload the contents of the &lt;code&gt;build&lt;/code&gt; folder to the chosen environment.&lt;/p&gt;

&lt;h3&gt;
  
  
  Environment Configuration
&lt;/h3&gt;

&lt;p&gt;Configuring the environment is critical for a successful deployment. I define environment variables for various settings in the &lt;code&gt;.env&lt;/code&gt; file. Key variables often include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;REACT_APP_API_URL&lt;/code&gt;: The URL of the backend API.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;REACT_APP_ENV&lt;/code&gt;: Specifies the current environment (development, staging, production).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When deploying, I set these variables directly in the hosting environment as needed. For instance, platforms like Netlify allow me to set these variables in their dashboard.&lt;/p&gt;

&lt;p&gt;Lastly, I verify the deployment by accessing the application and checking key functionalities to ensure everything runs smoothly.&lt;/p&gt;

</description>
      <category>react</category>
      <category>programming</category>
      <category>webdev</category>
      <category>javascript</category>
    </item>
    <item>
      <title>A Year of Transformation: Reflecting on 2024's Journey in Tech and Beyond</title>
      <dc:creator>Saurabh Sharma</dc:creator>
      <pubDate>Thu, 02 Jan 2025 05:32:00 +0000</pubDate>
      <link>https://dev.to/saurabh2k1/a-year-of-transformation-reflecting-on-2024s-journey-in-tech-and-beyond-coe</link>
      <guid>https://dev.to/saurabh2k1/a-year-of-transformation-reflecting-on-2024s-journey-in-tech-and-beyond-coe</guid>
      <description>&lt;p&gt;&lt;em&gt;This is a submission for the &lt;a href="https://dev.to/challenges/newyear"&gt;2025 New Year Writing challenge&lt;/a&gt;: Retro’ing and Debugging 2024.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;As we are ushering into a new year which is a perfect square &lt;strong&gt;2025&lt;/strong&gt; in mathematically terms it's time to pause and reflect on to the whirlwind that was 2024 back in the year that gone. &lt;/p&gt;

&lt;p&gt;The year 2024 was marked by remarkable advancements in technology, specially in the field of artificial intelligence (AI) and machine learning (ML).  The usage of AI into everyday applications reached new heights, making day to day tasks more efficient and in-turn creating more opportunities for innovation. Parallelly the challenges posed by cyber crimes also enhanced. We have seen global impacts due to misbehaving of application updates.&lt;/p&gt;

&lt;p&gt;on personal front also 2024 was a year of introspection and growth. Embracing new learning experiences in both professional development and personal hobbies. And as I say frequently, being in IT sector, you can not leave learning. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Always try to learn new things if you want to be relevant in ever evolving IT industry.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Achievements
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;First of all I promoted in my organization&lt;/li&gt;
&lt;li&gt;I have secured coveted &lt;em&gt;Certified Information Security Manager&lt;/em&gt; (CISM) certificate.&lt;/li&gt;
&lt;li&gt;Utilizing generative AI &lt;a href="https://chatgpt.com/c/677612e5-595c-8012-a968-7757eb026b6e" rel="noopener noreferrer"&gt;ChatGPT&lt;/a&gt; &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I was learning React JS front end and in this journey of self learning, I have achieved many milestone like utilizing &lt;a href="https://marmelab.com/react-admin/" rel="noopener noreferrer"&gt;react-admin framework&lt;/a&gt;. I also implemented two-factor authentication using &lt;a href="https://en.wikipedia.org/wiki/Google_Authenticator" rel="noopener noreferrer"&gt;Authenticator&lt;/a&gt; tools with react-admin framework. It was a very challenging job to include two-factor alongside react-admin authentication as there is no tutorial available for it. But this is very much required in the era of AI infused cyber threats to secure your applications. &lt;/p&gt;

</description>
      <category>devchallenge</category>
      <category>career</category>
      <category>learning</category>
      <category>cybersecurity</category>
    </item>
  </channel>
</rss>
