<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Rosni Farook on Medium]]></title>
        <description><![CDATA[Stories by Rosni Farook on Medium]]></description>
        <link>https://medium.com/@rosnifarook?source=rss-40d084c0fb43------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*OVtRksAA1ReQ6syRf3-dbQ.png</url>
            <title>Stories by Rosni Farook on Medium</title>
            <link>https://medium.com/@rosnifarook?source=rss-40d084c0fb43------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 08:05:52 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@rosnifarook/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Integrating Asgardeo Authentication into a MERN Application and Deploying on Choreo]]></title>
            <link>https://rosnifarook.medium.com/integrating-asgardeo-authentication-into-a-mern-application-and-deploying-on-choreo-5fe803d19db0?source=rss-40d084c0fb43------2</link>
            <guid isPermaLink="false">https://medium.com/p/5fe803d19db0</guid>
            <category><![CDATA[identity-acess-management]]></category>
            <category><![CDATA[wso2]]></category>
            <category><![CDATA[openid-connect]]></category>
            <category><![CDATA[choreo]]></category>
            <category><![CDATA[asgardeo]]></category>
            <dc:creator><![CDATA[Rosni Farook]]></dc:creator>
            <pubDate>Thu, 09 Oct 2025 14:37:24 GMT</pubDate>
            <atom:updated>2025-10-09T14:37:24.962Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2Air5DU3tr_aLcxvJoNKfw.png" /></figure><h3><strong>Introduction</strong></h3><p>Readify is a modern MERN-based book store application built with React, featuring rich browsing, a seamless cart/checkout flow, an order history, and an admin dashboard with real-time analytics.</p><p>Initially, the app used Firebase for authentication (including Google sign-in). To enhance security and provide an enterprise-ready login experience, I integrated Asgardeo from WSO2, which offers standards-based OpenID Connect (OIDC) and single sign-on (SSO). Users can continue with Firebase or choose a simplified Asgardeo login, while the backend APIs and admin routes remain protected and production-ready.</p><p>In this blog post, I’ll walk you through integrating Asgardeo into a React application and deploying both the frontend and backend on WSO2 Choreo using the Readify project as a case study. We’ll cover configuring Asgardeo, wiring the React app with the AuthProvider, handling the auth callback, setting up backend CORS and API management, and finalizing deployment on Choreo for a secure, scalable production setup.</p><h4>1. Setting up the project</h4><p><strong>a. Prerequisites</strong></p><p>Before starting, make sure you have the following ready:</p><ul><li>Node.js and npm installed</li><li>A MERN app (React frontend + Express backend + MongoDB)</li><li>Choreo account for deployment</li><li>Asgardeo account<strong> </strong>to register your application and get authentication credentials</li></ul><p><em>These prerequisites ensure you can run the app locally, integrate authentication, and deploy to Choreo.</em></p><p><strong>b. Create a React App (if you don’t have one)</strong></p><p>You can create a React project using Vite:</p><pre>npm create vite@latest my-react-app --template react<br>cd my-react-app<br>npm install</pre><p><strong>c. Installing Dependencies</strong></p><p>To integrate Asgardeo authentication, install the official SDK</p><pre>npm install @asgardeo/auth-react</pre><ul><li><strong>@asgardeo/auth-react </strong>provides hooks and components to handle OpenID Connect (OIDC) login, logout, and token management.</li><li>This package simplifies adding SSO functionality without writing custom OAuth flows.</li></ul><h4><strong>2. Configuring Asgardeo</strong></h4><p><strong>a. Registering Your App in Asgardeo Console</strong></p><p>1. Go to the <a href="https://console.asgardeo.io/">Asgardeo Console</a> and log in.<br>2. If you don’t have an organization, create one.<br>3. Navigate to <strong>Applications → New Application → Single-Page Application</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NbhfVwj38QcD_60G1iscbA.png" /><figcaption>Asgardeo Console SPA</figcaption></figure><p>4. Fill in the details:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MNYsrWqUfCP3Z7bFbAsUnQ.png" /><figcaption>SPA Creation Pop-up</figcaption></figure><ul><li><strong>Name:</strong> e.g: my-react-app</li><li><strong>Authorized Redirect URLs:</strong> <a href="https://08c118b9-7fba-4454-bbdc-1d315f882345.e1-us-east-azure.choreoapps.dev/auth/callback">https://08c118b9-7fba-4454-bbdc-1d315f882345.e1-us-east-azure.choreoapps.dev/auth/callback</a></li></ul><p>The Redirect URL in Asgardeo must exactly match the URL used in the frontend <strong>.env</strong> file. Here, I’ve used my Choreo production URL because the frontend is deployed there. For other environments, their URLs must also be added to Asgardeo.</p><p>5. Enable self-registration (optional)</p><p>Go to <strong>Login &amp; Registration → User Onboarding → Self Registration → Enable</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*90ptN2wjXaDfqTgn1I-nng.png" /><figcaption>Self-Registration Window</figcaption></figure><p>Go to <strong>Applications → [Your App] → Quick Start</strong> in Asgardeo, where you can <strong>view and collect the configuration values</strong> (Client ID, Base URL, Redirect URLs, etc.) for your React project’s .env file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sbTWuKiXodgyCIBoFJQ2AA.png" /><figcaption>Quick Start Window</figcaption></figure><p><strong>b. Adding Environment Variables</strong></p><p>Create a .env file in the root of your React project, or add the configuration to your existing .env file</p><pre>VITE_ASGARDEO_CLIENT_ID=your-client-id<br>VITE_ASGARDEO_BASE_URL=https://api.asgardeo.io/t/your-org<br>VITE_ASGARDEO_SIGNIN_REDIRECT_URL=https://your-app-domain/auth/callback<br>VITE_ASGARDEO_SIGNOUT_REDIRECT_URL=https://your-app-domain<br>VITE_ASGARDEO_SCOPE=openid,profile,email<br>VITE_ASGARDEO_STORAGE=localStorage</pre><ul><li>VITE_ASGARDEO_CLIENT_ID: Unique app ID from Asgardeo.</li><li>VITE_ASGARDEO_BASE_URL: Organization API endpoint.</li><li>VITE_ASGARDEO_SIGNIN_REDIRECT_URL: Where users go after login.</li><li>VITE_ASGARDEO_SIGNOUT_REDIRECT_URL: Where users go after logout.</li><li>VITE_ASGARDEO_SCOPE: Requested permissions (openid, profile, email).</li><li>VITE_ASGARDEO_STORAGE: Token storage location (localStorage or sessionStorage).</li></ul><p><strong>3. Wrapping Your App with AuthProvider</strong></p><p>In <strong>src/main.jsx</strong>, wrap your app with <strong>AuthProvider</strong> from <strong>@asgardeo/auth-react</strong></p><pre>import { AuthProvider } from &quot;@asgardeo/auth-react&quot;;<br>import { Provider } from &quot;react-redux&quot;;<br>import { RouterProvider } from &quot;react-router-dom&quot;;<br>import { store } from &quot;./redux/store.js&quot;;<br>import router from &quot;./routers/router.jsx&quot;;<br><br>&lt;AuthProvider<br>  config={{<br>    signInRedirectURL: import.meta.env.VITE_ASGARDEO_SIGNIN_REDIRECT_URL,<br>    signOutRedirectURL: import.meta.env.VITE_ASGARDEO_SIGNOUT_REDIRECT_URL,<br>    clientID: import.meta.env.VITE_ASGARDEO_CLIENT_ID,<br>    baseUrl: import.meta.env.VITE_ASGARDEO_BASE_URL,<br>    scope: import.meta.env.VITE_ASGARDEO_SCOPE.split(&quot;,&quot;),<br>    storage: import.meta.env.VITE_ASGARDEO_STORAGE,<br>  }}<br>&gt;<br>  &lt;Provider store={store}&gt;<br>    &lt;RouterProvider router={router} /&gt;<br>  &lt;/Provider&gt;<br>&lt;/AuthProvider&gt;</pre><p>Configuration Options</p><ul><li>AuthProvider provides authentication context to the whole app.</li><li><strong>signInRedirectURL</strong> &amp; <strong>signOutRedirectURL</strong>: Must match URLs in Asgardeo.</li><li><strong>scope</strong>: Permissions your app requests from users.</li><li><strong>storage (optional)</strong>: Determines whether tokens are kept in localStorage or sessionStorage.</li></ul><p><strong>Note:</strong> The <strong>&lt;Provider store={store}&gt; </strong>is used for Redux (e.g., Firebase state management) and <strong>&lt;RouterProvider&gt; </strong>is for React Router navigation. For the purpose of Asgardeo authentication setup, you can focus on the &lt;AuthProvider&gt; configuration and ignore the store/router parts.</p><p><strong>4. Handling Authentication State with Asgardeo</strong></p><p>To track the Asgardeo user across your app, we <strong>store user info and authentication state in a context</strong>. This lets any component know if the user is logged in and access their details like email or name.</p><p>AuthContext (Asgardeo Part)</p><pre>import { createContext, useContext, useEffect, useState } from &quot;react&quot;;<br>import { useAuthContext as useAsgardeo } from &quot;@asgardeo/auth-react&quot;;<br><br>const AuthContext = createContext();<br><br>export const useAuth = () =&gt; useContext(AuthContext);<br><br>export const AuthProvider = ({ children }) =&gt; {<br>  const [currentUser, setCurrentUser] = useState(null);<br>  const [loading, setLoading] = useState(true);<br><br>  // ---------------- Asgardeo ----------------<br>  const {<br>    state: asgState,<br>    signIn: asgSignIn,<br>    signOut: asgSignOut,<br>    getBasicUserInfo,<br>    getDecodedIDToken,<br>  } = useAsgardeo();<br><br>  const signInWithAsgardeo = async () =&gt; await asgSignIn();<br>  const logoutAsgardeo = async () =&gt; await asgSignOut();<br><br>  // Sync Asgardeo user → currentUser<br>  useEffect(() =&gt; {<br>    let cancelled = false;<br><br>    const syncAsgUser = async () =&gt; {<br>      if (asgState?.isAuthenticated) {<br>        try {<br>          const basic = await getBasicUserInfo();<br>          const decoded = await getDecodedIDToken();<br>          const email =<br>            basic?.email || decoded?.email || decoded?.username || null;<br><br>          if (!cancelled) {<br>            setCurrentUser({<br>              email,<br>              displayName: basic?.name || decoded?.given_name || email,<br>              photoURL: basic?.picture || null,<br>              provider: &quot;asgardeo&quot;,<br>            });<br>            setLoading(false);<br>          }<br>        } catch {<br>          if (!cancelled) setLoading(false);<br>        }<br>      }<br>    };<br><br>    syncAsgUser();<br>    return () =&gt; {<br>      cancelled = true;<br>    };<br>  }, [asgState?.isAuthenticated]);<br>  // ------------------------------------------<br><br>  const value = {<br>    currentUser,<br>    loading,<br>    signInWithAsgardeo,<br>    logoutAsgardeo,<br>  };<br><br>  return &lt;AuthContext.Provider value={value}&gt;{children}&lt;/AuthContext.Provider&gt;;<br>};</pre><p>Explanation</p><ul><li><strong>useAuthContext</strong>: Gives access to Asgardeo login state and helper functions.</li><li><strong>asgState.isAuthenticated</strong>: Tells if the user is logged in.</li><li><strong>getBasicUserInfo()</strong> &amp; <strong>getDecodedIDToken()</strong>: Fetch user info like email, name, and profile picture.</li><li><strong>currentUser</strong>: Stores the logged-in user info for your app to use.</li><li><strong>signInWithAsgardeo()</strong> &amp; <strong>logoutAsgardeo()</strong>: Functions to log in/out.</li><li><strong>useEffect</strong>: Automatically syncs the Asgardeo user info whenever authentication status changes.</li></ul><p><strong>5. Auth Callback Component</strong></p><p>After login, Asgardeo redirects back to your app. Handle this with a callback component.</p><pre>// src/pages/AuthCallback.jsx<br>import React, { useEffect } from &quot;react&quot;;<br>import { useNavigate } from &quot;react-router-dom&quot;;<br>import { useAuthContext as useAsgardeo } from &quot;@asgardeo/auth-react&quot;;<br>import Loading from &quot;../components/Loading&quot;;<br><br>const AuthCallback = () =&gt; {<br>  const navigate = useNavigate();<br>  const { state } = useAsgardeo();<br><br>  useEffect(() =&gt; {<br>    if (state?.isAuthenticated) {<br>      navigate(&quot;/&quot;, { replace: true });<br>    }<br>  }, [state?.isAuthenticated, navigate]);<br><br>  return &lt;Loading /&gt;;<br>};<br><br>export default AuthCallback;</pre><p>Explanation</p><ul><li>Redirects users to the home page after login.</li><li>Displays a <strong>loading state</strong> while authentication completes.</li></ul><p><strong>6. Adding Login/Logout in Components</strong></p><p>In the Login.jsx file, we call the <strong>signInWithAsgardeo()</strong> function from our AuthContext. When clicked, it redirects users to Asgardeo’s secure login page.</p><pre>// src/pages/Login.jsx<br>import React from &quot;react&quot;;<br>import { useAuth } from &quot;../context/AuthContext&quot;;<br>import asgardeoLogo from &quot;../assets/asgardeo.svg&quot;;<br><br>const Login = () =&gt; {<br>  const { signInWithAsgardeo } = useAuth();<br><br>  const handleAsgardeoSignIn = async () =&gt; {<br>    try {<br>      await signInWithAsgardeo(); // Redirects to Asgardeo login page<br>    } catch (error) {<br>      alert(&quot;Asgardeo sign-in failed!&quot;);<br>      console.error(error);<br>    }<br>  };<br><br>  return (<br>    &lt;div className=&quot;h-[calc(100vh-120px)] flex justify-center items-center&quot;&gt;<br>      &lt;div className=&quot;w-full max-w-sm px-8 py-6 bg-white rounded shadow-md&quot;&gt;<br>        &lt;h2 className=&quot;mb-4 text-xl font-semibold text-center&quot;&gt;<br>          Sign in to your account<br>        &lt;/h2&gt;<br><br>        {/* Asgardeo Sign-in Button */}<br>        &lt;button<br>          onClick={handleAsgardeoSignIn}<br>          className=&quot;flex items-center justify-center w-full gap-2 px-4 py-2 font-bold text-black bg-gray-300 rounded hover:bg-blue-700 hover:text-white focus:outline-none&quot;<br>        &gt;<br>          &lt;img src={asgardeoLogo} alt=&quot;Asgardeo&quot; width={20} height={20} /&gt;<br>          &lt;span&gt;Sign in with Asgardeo&lt;/span&gt;<br>        &lt;/button&gt;<br><br>        &lt;p className=&quot;mt-5 text-xs text-center text-gray-500&quot;&gt;<br>          &amp;copy; 2025 Readify. All rights reserved.<br>        &lt;/p&gt;<br>      &lt;/div&gt;<br>    &lt;/div&gt;<br>  );<br>};<br><br>export default Login;</pre><p>Explanation</p><ul><li><strong>useAuth()—Imports</strong> Asgardeo auth functions from AuthContext.</li><li><strong>signInWithAsgardeo()</strong>—Opens Asgardeo’s login screen for the user.</li><li><strong>handleAsgardeoSignIn()</strong> — Handles the click event safely with try…catch.</li></ul><h4><strong>Deploying Your App on Choreo</strong></h4><p>Choreo simplifies deployment of MERN apps by handling backend services, frontend web apps, database connections, and environment variables. We’ll follow a structured approach: deploying the backend first, then the frontend, and connecting them securely</p><ol><li><strong>Create the Project in Choreo</strong></li></ol><ul><li>Log in to <a href="https://console.choreo.dev/">Choreo Console</a></li><li>Click <strong>Create Project</strong> → name it “your-project-name”</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jyLsNBQptDtwcM0_Ve-vVA.png" /><figcaption>Create Project Window</figcaption></figure><p>After that, in your project, click “create” to create the component. Just ignore the Readify Frontend and Readify Backend in the component listing since I have already created that component. It’s because it’s showing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6ac2b2o-JvK8hkWtrxdlvA.png" /></figure><p>We’ll follow a structured approach: deploying the backend first, then the frontend</p><ol><li><strong>Create a Service Component for the Backend</strong></li></ol><ul><li>In the <strong>Choreo Console</strong>, go to your project → <strong>Create Component</strong> → <strong>Service</strong>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZIUH1Ur0lNlA-Nkjze44JA.png" /></figure><ul><li>Provide a <strong>name</strong> (e.g., your-app-backend)</li><li>Connect your <strong>GitHub repository</strong> or upload your backend code directly</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HCfYnjeVYy8DQAGpx82y6A.png" /></figure><ul><li><strong>Display Name</strong>—Give your service a name, e.g., “Readify Frontend”.</li><li>Select the <strong>Node.js buildpack</strong></li><li><strong>Schema Path (Optional)</strong>—If you have an OpenAPI specification (openapi.yaml), provide the path so Choreo can manage your API.</li><li><strong>Language Version</strong> — Select the Node.js version compatible with your project (e.g., Node 20.x).</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9dc1KDUE3q5E_RTAcrUbjg.png" /></figure><p>After filling in these details, click <strong>Create &amp; Deploy</strong>.</p><p><strong>Set Environment Variables</strong></p><p>After deploying the backend service, you need to configure environment variables for things like your MongoDB connection string and JWT Secret, Frontend URL.</p><ul><li>Go to <strong>DevOps → Configs &amp; Secrets</strong> in the Choreo Console.</li><li>Select <strong>Environment Variables</strong>.</li></ul><p>You have two options for setting environment variables: you can add them manually, creating each one individually, or you can import your <strong>.env </strong>file directly to quickly configure all variables at once.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xztmnuJWHCUZmadLog6xbA.png" /></figure><p>You can test your API endpoints by navigating to <strong>Test → Console</strong> in the Choreo Console. This allows you to make requests to your APIs directly, verify responses, and ensure that your backend is working correctly before connecting it to the frontend</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pCo8xhkXZevxGXC1552HPg.png" /></figure><p><strong>Deploy</strong> tab inside the Choreo Console. Here, you can view your deployed service, promote it between <strong>Development</strong> and <strong>Production</strong> environments, and access the live URLs for your backend or frontend applications. Choreo also provides a <strong>Manage Authentication</strong> section, where you can configure login, logout, and error handling for your web app. Since Readify already uses Asgardeo for authentication, you can <strong>disable Choreo’s managed authentication</strong> to avoid conflicts, but you can explore this feature later if you want Choreo to handle authentication automatically</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z-fqa2tdUlo591gMIIZogg.png" /></figure><p><strong>2. Create a Web Application Component for the Frontend</strong></p><p>To create a <strong>Web Application</strong> component in Choreo</p><ul><li><strong>Display Name</strong>—Give your web application a name, e.g., “Readify Backend”.</li><li><strong>Repository</strong>—Connect your GitHub repository</li><li><strong>Component Directory</strong>—Provide the root directory of your frontend code.</li><li><strong>Build Preset</strong>—React</li><li><strong>Build Command</strong>—npm run build</li><li><strong>Node Version</strong>—Choose the Node.js version compatible with your project.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z65hu5zewqyUFnih03glMg.png" /></figure><p>After filling in these details, click <strong>Create &amp; Deploy</strong>.</p><p>After creating and deploying your frontend web application, you need to set environment variables <strong>the same way you did for the backend</strong>. Navigate to <strong>DevOps → Configs &amp; Secrets</strong> in the Choreo Console, select <strong>Environment Variables</strong>, and either add them manually or import your .env file. Once configured, go back to the <strong>Deploy</strong> tab and click <strong>Redeploy</strong> to apply the changes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5VlmUOMYcAYWqQo72TvtOQ.png" /></figure><p><strong>Summary</strong></p><p>In Readify, users can log in via <strong>Firebase</strong> or <strong>Asgardeo</strong>, with both storing user data in Firestore. Integrating Asgardeo makes authentication secure, flexible, and seamless, while Choreo simplifies deploying the application to production. Key points to keep in mind:</p><ul><li>Provide separate login options for Firebase and Asgardeo.</li><li>Store user data in Firestore with a unique identifier (Asgardeo’s sub or Firebase’s uid).</li><li>Ensure logout clears the correct session and data from browser storage depending on the authentication provider.</li><li>Wrap your app with AuthProvider from @asgardeo/auth-react to provide authentication context.</li><li>Use React Context (AuthContext) to manage and sync Asgardeo user state.</li><li>Deploy the backend as a <strong>Service</strong> and the frontend as a <strong>Web Application</strong> on Choreo.</li><li>Set environment variables for both backend and frontend and promote apps from development to production.</li><li>Test APIs and ensure proper connectivity between frontend and backend.</li></ul><p>Following these steps makes Readify fully functional, secure, and production-ready, with a live frontend and backend on Choreo and enterprise-grade authentication via Asgardeo.</p><p>For advanced features like token management, route protection, or multi-provider handling, refer to the <a href="https://wso2.com/asgardeo/docs/">Asgardeo documentation</a> and explore the Readify source code on <a href="https://github.com/rosnifarook/readify-app-frontend.git">GitHub</a>.</p><p><strong>Try the Readify app live:</strong> <a href="https://08c118b9-7fba-4454-bbdc-1d315f882345.e1-us-east-azure.choreoapps.dev/">https://08c118b9-7fba-4454-bbdc-1d315f882345.e1-us-east-azure.choreoapps.dev</a></p><p><strong>References</strong></p><p><a href="https://wso2.com/asgardeo/docs/">https://wso2.com/asgardeo/docs/</a></p><p><a href="https://wso2.com/choreo/docs/">https://wso2.com/choreo/docs/</a></p><p><a href="https://github.com/asgardeo/asgardeo-auth-react-sdk?source=post_page-----631e0d6e68ff---------------------------------------">https://github.com/asgardeo/asgardeo-auth-react-sdk?source=post_page-----631e0d6e68ff---------------------------------------</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5fe803d19db0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a SpringBoot User Management System with MongoDB]]></title>
            <link>https://rosnifarook.medium.com/building-a-springboot-user-management-system-with-mongodb-164d85a7bbf9?source=rss-40d084c0fb43------2</link>
            <guid isPermaLink="false">https://medium.com/p/164d85a7bbf9</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[mongodb]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[spring-boot]]></category>
            <dc:creator><![CDATA[Rosni Farook]]></dc:creator>
            <pubDate>Wed, 02 Aug 2023 04:59:59 GMT</pubDate>
            <atom:updated>2023-08-02T04:59:59.894Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dP9TU0ZjzSIEO8are8ATZA.jpeg" /></figure><h3>Introduction</h3><p>In this article, we’ll walk you through the steps involved in installing MongoDB, choose the best programming language, connecting to the server, and building an intuitive login form with insert, update, and delete functionality.</p><p><strong><em>Procedure 1: </em>MongoDB Installation</strong></p><p>Let’s start by installing MongoDB, a NoSQL database that’s perfect for our User Management System. But first, let’s understand why MongoDB is such a great choice.</p><p>Why choose MongoDB?<br>MongoDB stands out because of its document-oriented approach, which allows us to store and manage various data types effortlessly. Unlike traditional relational databases, MongoDB doesn’t rely on fixed table structures, giving us the freedom to adapt and change our data as our application evolves.</p><p>One of the key advantages is MongoDB’s support for ACID transactions, ensuring data integrity during complex operations involving multiple documents. This means our User Management System can rely on the database to maintain consistency and reliability.</p><p>Furthermore, MongoDB’s horizontal scalability means it can efficiently handle growing amounts of data by distributing it across multiple servers or clusters. This ensures optimal performance and high availability, making MongoDB an excellent choice for applications expecting significant growth.</p><p><strong><em>Step 1 :</em></strong> <em>Click this link which would directly download </em><a href="https://fastdl.mongodb.org/windows/mongodb-windows-x86_64-6.0.8-signed.msi"><em>https://fastdl.mongodb.org/windows/mongodb-windows-x86_64-6.0.8-signed.msi</em></a></p><p>double click on the .msi package you just downloaded. This will launch the installation wizard.</p><p><strong><em>Step 2: </em></strong><em>Click Next to Start installation</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/497/0*I3m3H9nVtGXf1Qhc.png" /></figure><p>Accept license agreement</p><p><strong><em>Step 3: </em></strong><em>Select Setup Type as ‘COMPLETE’</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/495/0*OU0p79w7ZJ5HM2Dl.png" /></figure><p><strong><em>Step 4: </em></strong><em>Select “Run service as Network Service user” and make a note of the data directory, we’ll need this later.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/0*JJ0VkPKkuJgBnKvp.png" /></figure><p><strong><em>Step 4: </em></strong><em>We will need Mongo Compass, so select it and click Next.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/495/0*7Fv3URN999X3uLnS.png" /></figure><p><strong><em>Step 5: </em></strong><em>Click Install to begin installation.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/496/0*n4QnPNuvyp4o26X8.png" /></figure><p><strong><em>Step : 6 : </em></strong><em>Hit Finish to complete installation.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*2X4Kyp4RdkE-Zem6.png" /></figure><p><strong><em>Step 7: </em></strong><em>MongoBD compass configuration.</em></p><p>To connect to your local MongoDB, you set Hostname to localhost and Port to 27017. These values are the default for all local MongoDB connections (unless you changed them).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*WruK5wG2uDoAgLL4.png" /></figure><p>Click the plus symbol next to the database to create a database.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*xChC32HAdIF7j2E_.png" /></figure><p>Provide the same collection name as the document annotation name in the user class.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*SSGN1KKbQI96jEbk.png" /></figure><p>Inserted collection list</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*OsSatAZbSiSgNqRy.png" /></figure><blockquote><strong><em>Procedure 2: Creating a SpringBoot Application</em></strong></blockquote><p><strong><em>Step 1: </em></strong><em>Install IntelliJ IDEA on the local machine</em></p><p><strong><em>Step 2: </em></strong><em>Create a Spring Boot Project in Spring Initializr</em></p><p>Go to <a href="https://start.spring.io/">https://start.spring.io/</a> and create a Spring Boot project. Please fill in all the details accordingly and at last click on the <strong>GENERATE </strong>button below. This will download your Spring Boot project in zip format. Now extract the folder into your local machine.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*av7Jhfa_J1KGgoYn.jpeg" /></figure><p><strong><em>Step 3: </em></strong><em>Import Spring Boot Project in IntelliJ IDEA</em></p><p>Go to the IntelliJIDE for Enterprise Java and Select <strong>Open</strong> as shown in the below image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/784/1*9TOar5my9SSp1QoRTUt8Bw.png" /></figure><p><strong><em>Step 4: </em></strong><em>Now select the extracted zip file that has been generated.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/630/1*2KWnQofs02qZyPf406slYg.png" /></figure><p><strong><em>Step 5: </em></strong><em>Finally, click the </em><strong><em>OK</em></strong><em> button to finish importing the Spring Boot project into the Intelji IDE.</em></p><blockquote><strong>To establish a connection between a Spring Boot application and MongoDB, follow these simple steps:</strong></blockquote><p><strong><em>Step 1: </em></strong><em>Open the “application.properties” file located in the “src/main” directory of your Spring Boot project.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/446/0*DbAF4vWPNSP--P5h.png" /></figure><p><strong><em>Step 2: </em></strong><em>Add the following lines to configure the MongoDB connection:</em></p><pre>server.port=8081 <br>spring.data.mongodb.host=localhost<br>spring.data.mongodb.port=27017<br>spring.data.mongodb.database=user_management_db<br>spring.jackson.default-property-inclusion=NON_NULL</pre><p><em># If not specified, the default port is 8080<br># Specify the MongoDB server port number<br># Specify the name of the MongoDB database to use<br># Include only non-null values in JSON serialization</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*a1dQTpmwHJXMeLFl.png" /></figure><p>Next, follow these additional steps:</p><p><strong><em>Step 1:</em></strong></p><p>Create packages:</p><ul><li>Inside the “src/main/java” directory, create the following packages:</li><li>com.example.userManagementWithMongoDB.data</li><li>com.example.userManagementWithMongoDB.service</li><li>com.example.userManagementWithMongoDB.controller</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/494/0*3n5c7j0tA85M5mCo.png" /></figure><p>Create the “User” class:</p><p>Add this code below</p><p>Certainly! Here’s the code again:</p><pre>package com.example.userManagementWithMongoDB.data;</pre><pre>import org.springframework.data.annotation.Id;<br>import org.springframework.data.mongodb.core.mapping.Document;@Document(collection = &quot;user&quot;)<br>public class User {    @Id<br>    private String id;<br>    private String firstName;<br>    private String lastName;<br>    private String address;<br>    private String occupation;    public User(String id, String firstName, String lastName, String address, String occupation) {<br>        this.id = id;<br>        this.firstName = firstName;<br>        this.lastName = lastName;<br>        this.address = address;<br>        this.occupation = occupation;<br>    }    public String getId() {<br>        return id;<br>    }    public void setId(String id) {<br>        this.id = id;<br>    }    public String getFirstName() {<br>        return firstName;<br>    }    public void setFirstName(String firstName) {<br>        this.firstName = firstName;<br>    }    public String getLastName() {<br>        return lastName;<br>    }    public void setLastName(String lastName) {<br>        this.lastName = lastName;<br>    }    public String getAddress() {<br>        return address;<br>    }    public void setAddress(String address) {<br>        this.address = address;<br>    }    public String getOccupation() {<br>        return occupation;<br>    }    public void setOccupation(String occupation) {<br>        this.occupation = occupation;<br>    }<br>}</pre><p><strong>Let’s explain the code step by step:</strong></p><p>Sure! Let’s explain the code step by step:</p><ol><li>Package and Import Statements:</li></ol><pre>package com.example.userManagementWithMongoDB.data;</pre><pre>import org.springframework.data.annotation.Id;<br>import org.springframework.data.mongodb.core.mapping.Document;</pre><p>In the first lines, we declare the package name where our class “User” belongs. We also import the necessary annotations from Spring Framework.</p><p>2. Class Declaration and Annotations:</p><pre>@Document(collection = &quot;user&quot;)<br>public class User {</pre><p>Here, we define the “User” class and annotate it with @Document. This annotation tells Spring Data MongoDB that instances of this class should be stored in a MongoDB collection called &quot;user&quot;.</p><p>3. Fields (Properties):</p><pre>@Id<br>    private String id;<br>    private String firstName;<br>    private String lastName;<br>    private String address;<br>    private String occupation;</pre><p>The class has five fields, which represent the properties of a user:</p><ul><li>id: This field is annotated with @Id, indicating that it is the unique identifier for each user. MongoDB will use this field as the document identifier when storing data.</li><li>firstName: This field will store the first name of the user.</li><li>lastName: This field will store the last name of the user.</li><li>address: This field will store the address of the user.</li><li>occupation: This field will store the occupation of the user.</li></ul><p>4. Constructor:</p><pre>public User(String id, String firstName, String lastName, String address, String occupation) {<br>        this.id = id;<br>        this.firstName = firstName;<br>        this.lastName = lastName;<br>        this.address = address;<br>        this.occupation = occupation;<br>    }</pre><p>The class has a constructor that allows you to create a new instance of the “User” class with all the required fields. The constructor sets the provided values to the corresponding fields.</p><p>5. Getter and Setter Methods:</p><pre>public String getId() {<br>        return id;<br>    }</pre><pre>public void setId(String id) {<br>        this.id = id;<br>    }    public String getFirstName() {<br>        return firstName;<br>    }    public void setFirstName(String firstName) {<br>        this.firstName = firstName;<br>    }    // Similar getter and setter methods for other fields...</pre><p>The class has getter and setter methods for each field. These methods allow you to access and modify the values of the “User” object’s properties</p><p><strong><em>Step 3: </em></strong>Create the UserRepository interface inside the data package:</p><pre>package com.example.userManagementWithMongoDB.data;</pre><pre>import org.springframework.data.mongodb.repository.MongoRepository;<br>import org.springframework.stereotype.Repository;@Repository<br>public interface UserRepository extends MongoRepository&lt;User, String&gt; {}</pre><p>Explanation:</p><ol><li>UserRepository is an interface that extends MongoRepository: In Spring Data, repositories are interfaces that define data access methods for working with a specific entity (in this case, the User entity). By extending MongoRepository&lt;User, String&gt;, this interface inherits various CRUD (Create, Read, Update, Delete) methods provided by Spring Data for working with MongoDB.</li><li>User is the entity type: The first type parameter &lt;User&gt; specifies the entity type that the repository will handle, which is the User class in this case.</li><li>String is the ID type: The second type parameter &lt;String&gt; indicates the type of the unique identifier (ID) used by the User entity. In this example, the id field of the User class is of type String.</li><li>@Repository annotation: This annotation is used to mark UserRepository as a Spring Data repository bean. Spring will automatically create an instance of this repository during application startup, allowing you to use it for data access and persistence operations without the need for manual instantiation.</li></ol><p><strong><em>Step 4:</em></strong><em>Create the </em><em>UserController class inside the </em><em>controller package:</em></p><pre>package com.example.userManagementWithMongoDB.controller;</pre><pre>import com.example.userManagementWithMongoDB.data.User;<br>import com.example.userManagementWithMongoDB.service.UserService;<br>import org.springframework.beans.factory.annotation.Autowired;<br>import org.springframework.web.bind.annotation.*;</pre><pre>import java.util.List;</pre><pre>@RestController<br>@CrossOrigin(origins = &quot;*&quot;)<br>@RequestMapping(&quot;/api&quot;)<br>public class UserController {</pre><pre>    @Autowired<br>    private UserService userService;</pre><pre>    @GetMapping(path=&quot;/users&quot;)<br>    public List&lt;User&gt; getAllUsers(){<br>        return userService.getAllUser();<br>    }</pre><pre>    @PostMapping(path=&quot;/users&quot;)<br>    public User createUser(@RequestBody User user){<br>        return userService.createUser(user);<br>    }</pre><pre>    @PutMapping(path=&quot;/users/{id}&quot;)<br>    public User updateUser(@RequestBody User user, @PathVariable(name = &quot;id&quot;) String id){<br>        user.setId(id);<br>        userService.updateUser(user);<br>        return user;<br>    }</pre><pre>    @DeleteMapping(path=&quot;/users/{id}&quot;)<br>    public void deleteUserById(@PathVariable String id){<br>        userService.deleteUserById(id);<br>    }<br>}</pre><p>Explanation:</p><ol><li>UserController class: This class is a Spring MVC controller responsible for handling incoming HTTP requests related to user management.</li><li>@RestController annotation: This annotation indicates that this class is a RESTful controller that will handle HTTP requests and produce JSON responses.</li><li>@CrossOrigin(origins = &quot;*&quot;) annotation: This annotation allows Cross-Origin Resource Sharing (CORS) for all origins, enabling the controller to accept requests from any domain. In a production environment, you should restrict this to specific origins.</li><li>@RequestMapping(&quot;/api&quot;) annotation: This annotation maps all the controller&#39;s endpoints under the base URL path &quot;/api&quot;. For example, the endpoint for getting all users will be &quot;/api/users&quot;.</li><li>@Autowired annotation: This annotation injects an instance of the UserService into the UserController, allowing it to use the service to interact with the business logic and data layer.</li><li>@GetMapping(path=&quot;/users&quot;): This method is mapped to handle HTTP GET requests with the URL path &quot;/api/users&quot;. It calls the getAllUser() method of the UserService and returns a list of all users as JSON response.</li><li>@PostMapping(path=&quot;/users&quot;): This method is mapped to handle HTTP POST requests with the URL path &quot;/api/users&quot;. It receives a JSON payload representing a new user, calls the createUser() method of the UserService, and returns the newly created user as a JSON response.</li><li>@PutMapping(path=&quot;/users/{id}&quot;): This method is mapped to handle HTTP PUT requests with the URL path &quot;/api/users/{id}&quot;. It receives a JSON payload representing the updated user data and the user ID in the URL path. It calls the updateUser() method of the UserService to update the user&#39;s data and returns the updated user as a JSON response.</li><li>@DeleteMapping(path=&quot;/users/{id}&quot;): This method is mapped to handle HTTP DELETE requests with the URL path &quot;/api/users/{id}&quot;. It receives the user ID in the URL path and calls the deleteUserById() method of the UserService to delete the user with the specified ID.</li></ol><p><strong><em>Step 4:</em></strong><em>Create the </em><em>UserService class inside the </em><em>service package:</em></p><pre>package com.example.userManagementWithMongoDB.service;</pre><pre>import com.example.userManagementWithMongoDB.data.User;<br>import com.example.userManagementWithMongoDB.data.UserRepository;<br>import org.springframework.beans.factory.annotation.Autowired;<br>import org.springframework.stereotype.Service;</pre><pre>import java.util.List;</pre><pre>@Service<br>public class UserService {</pre><pre>    @Autowired<br>    private UserRepository userRepository;</pre><pre>    public List&lt;User&gt; getAllUser(){<br>        List&lt;User&gt; user = userRepository.findAll();<br>        return user;<br>    }</pre><pre>    public User createUser(User user){<br>        return userRepository.save(user);<br>    }</pre><pre>    public User updateUser(User user){<br>        return userRepository.save(user);<br>    }</pre><pre>    public void deleteUserById(String id){<br>        userRepository.deleteById(id);<br>    }<br>}</pre><p>Explanation:</p><ol><li>UserService class: This class is a service component responsible for handling business logic related to user management.</li><li>@Service annotation: This annotation indicates that UserService is a Spring service bean. Spring will automatically create an instance of this service during application startup, allowing it to be used in other parts of the application without explicit instantiation.</li><li>@Autowired annotation: This annotation injects an instance of the UserRepository into the UserService, allowing it to interact with the MongoDB database for user data operations.</li><li>getAllUser() method: This method retrieves all users from the database by calling the findAll() method of the UserRepository and returns the list of users.</li><li>createUser(User user) method: This method saves a new user to the database by calling the save() method of the UserRepository. It receives a User object as a parameter and returns the saved user.</li><li>updateUser(User user) method: This method updates an existing user in the database. It also uses the save() method of the UserRepository, which can perform both create and update operations. It receives a User object representing the updated user and returns the updated user.</li><li>deleteUserById(String id) method: This method deletes a user from the database by calling the deleteById() method of the UserRepository. It receives the ID of the user to be deleted as a parameter.</li></ol><p><strong><em>Step 5: </em></strong><em>Then Open the </em><em>UserManagementWithMongoDbApplication class and click start to the Spring Boot application and run the backend</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*jDjnOMg2IM6KyJiV.png" /></figure><blockquote><strong><em>Procedure 3: Checking REST endpoints using the POST-MAN tool</em></strong></blockquote><p><strong>Step 1</strong>: <em>Downloading POSTMAN and installing</em></p><p><em>Visit the </em><a href="https://www.postman.com/"><em>https://www.postman.com/</em></a><em> website using any web browser.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*REiUd0J2FMEj2Wwg.PNG" /></figure><p>Click on Windows Button to download.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*7J3XBeJGu5J8DO9W.PNG" /></figure><p>Now click on Windows 64 — bit button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*ZT6LbqKyFWgIJm2h.PNG" /></figure><p>Now check for the executable file in downloads in your system and run it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/322/0*8_1EEQrOmxUmUlQX.PNG" /></figure><p>Now installing process will start it takes a minute to install in the system.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/571/0*oEHji7qeFcW3OSUc.PNG" /></figure><p>After installing the program the software opens automatically. Now you can see the interface of the software.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*R2fYMOSnYJHmRT40.PNG" /></figure><p><strong><em>Step 2: </em></strong><em>Checking if backend is working using POSTMAN</em></p><ol><li><strong>POST method</strong></li></ol><p>I — II — III — IV — V —</p><p>I. Open Postman: Launch the Postman application on your computer.</p><p>II. Set the Request Type and URL:</p><ul><li><em>Select “POST” from the dropdown menu next to the URL input field.</em></li><li><em>Enter the URL as </em><a href="http://localhost:8081/api/users."><em>http://localhost:8081/api/users.</em></a></li></ul><p>III. Set Headers:</p><ul><li><em>Click on the “Headers” tab (next to the “Params” tab).</em></li><li><em>Add a new header with the key “Content-Type” and value “application/json”. This header tells the backend that you are sending JSON data in the request body.</em></li></ul><p>IV. Set Request Body:</p><ul><li><em>Click on the “Body” tab.</em></li><li><em>Select the “raw” option.</em></li><li><em>From the dropdown menu, choose “JSON” as the data type.</em></li><li><em>In the text area below, paste the following JSON data:</em></li></ul><pre>{<br>    &quot;firstName&quot;: &quot;Ahamed&quot;,<br>    &quot;lastName&quot;: &quot;Ibrahim&quot;,<br>    &quot;address&quot;: &quot;No 59A Galle Road, Dehiwala&quot;,<br>    &quot;occupation&quot;: &quot;Software Engineer&quot;<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*2Ayk6jB7X1sVPtyZ.jpeg" /></figure><p>A. Send the Request:</p><ul><li><em>Click the “Send” button to send the POST request to the URL.</em></li></ul><p>B. Check the Response:</p><ul><li><em>After sending the request, you should receive a response from the backend.</em></li><li><em>The response will likely include a JSON object representing the user data you just created. It may also contain an “id” field, which is automatically generated by MongoDB when the user is saved to the database.</em></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*D2XsqpMKEyftfGSt.jpeg" /></figure><p><strong>2. GET Response:</strong></p><p>I — II — III — IV — V —</p><p>I. Set the Request Type and URL:</p><ul><li><em>Select “GET” from the dropdown menu next to the URL input field.</em></li><li><em>Enter the URL as </em><a href="http://localhost:8081/api/users."><em>http://localhost:8081/api/users</em></a></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*WvyuXi-pg7CnnmLN.jpeg" /></figure><p>II. Send the Request:</p><ul><li><em>Click the “Send” button to send the GET request to the specified URL.</em></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*-IDzU5NRtXUzX7fJ.jpeg" /></figure><p><strong>3. Update method</strong></p><p>I. Set the Request Type and URL:</p><ul><li><em>Select “PUT” from the dropdown menu next to the URL input field.</em></li><li><em>Enter the URL as </em><a href="http://localhost:8081/api/users/60f3194c45a1175b0e2bfecb."><em>http://localhost:8081/api/users/60f3194c45a1175b0e2bfecb</em></a></li><li><em>Users should replace </em><em>&quot;Updated First Name&quot;, </em><em>&quot;Updated Last Name&quot;, </em><em>&quot;Updated Address&quot;, and </em><em>&quot;Updated Occupation&quot; with the new values they want to set for the corresponding properties. The </em><em>id should be the same as the user&#39;s existing ID to update the correct user record.</em></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*6MKZr4Ou1wMxb5h6.jpeg" /></figure><p>II. Now check the the updated profile by entering the URL along with ID</p><ul><li><a href="http://localhost:8081/api/users/60f3194c45a1175b0e2bfecb."><em>http://localhost:8081/api/users/60f3194c45a1175b0e2bfecb</em></a></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*IWpP7_MhOg-EUKFJ.jpeg" /></figure><p><strong>4. Delete Method:</strong></p><p>I. Set the Request Type and URL:</p><ul><li><em>Select “DELETE” from the dropdown menu next to the URL input field.</em></li><li><em>Enter the URL. replace the ID </em><a href="http://localhost:8081/api/users/60f3194c45a1175b0e2bfecb."><em>http://localhost:8081/api/users/60f3194c45a1175b0e2bfecb.</em></a></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*v9PoK7N8Drf5_QIN.jpeg" /></figure><p><strong><em>Procedure 4: Creating a React App Using Visual Code</em></strong></p><p><strong><em>Step 1: Set Up the React Project</em></strong></p><p>I. Open Visual Studio Code and create a new folder for your React project.</p><p>II. Open a terminal in Visual Studio Code and navigate to the project folder.</p><p>III .Initialize a new React project using Create React App:</p><ul><li>npx create-react-app user-management</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*cvaVEnx97u14Pex5.png" /></figure><ul><li>The project name here is user-management</li></ul><p>IV. Navigate into the newly created project folder:</p><ul><li>cd user-management</li></ul><p>V. Open your project in Visual Studio by entering this code:</p><pre>code .</pre><p><strong><em>Step 2: Install Dependencies</em></strong></p><p>I . Install Axios for making API requests to the backend along with bootstap.</p><pre>npm install axios</pre><pre>npm install bootstrap@5.3.1</pre><p>A. Inside the “src” folder, create a new folder named “components.”</p><p>B. Create a new file named “User.jsx” inside the “components” folder.</p><p>C. Open the “User.jsx” file and add the following code:</p><pre>// User.jsx<br>import React, { useEffect, useState } from &#39;react&#39;;<br>import axios from &#39;axios&#39;;</pre><pre>function User() {<br>  const [id, setId] = useState(&#39;&#39;);<br>  const [firstName, setFirstName] = useState(&#39;&#39;);<br>  const [lastName, setLastName] = useState(&#39;&#39;);<br>  const [address, setAddress] = useState(&#39;&#39;);<br>  const [occupation, setOccupation] = useState(&#39;&#39;);<br>  const [users, setUsers] = useState([]);  useEffect(() =&gt; {<br>    Load();<br>  }, []);  async function Load() {<br>    const result = await axios.get(&#39;http://localhost:8081/api/users&#39;);<br>    setUsers(result.data);<br>    console.log(result.data);<br>  }  async function save(event) {<br>    event.preventDefault();<br>    try {<br>      await axios.post(&#39;http://localhost:8081/api/users&#39;, {<br>        firstName: firstName,<br>        lastName: lastName,<br>        address: address,<br>        occupation: occupation,<br>      });<br>      alert(&#39;User Registration Successfully&#39;);<br>      setId(&#39;&#39;);<br>      setFirstName(&#39;&#39;);<br>      setLastName(&#39;&#39;);<br>      setAddress(&#39;&#39;);<br>      setOccupation(&#39;&#39;);<br>      Load();<br>    } catch (err) {<br>      alert(&#39;User Registration Failed&#39;);<br>    }<br>  }  async function editUser(user) {<br>    setFirstName(user.firstName);<br>    setLastName(user.lastName);<br>    setAddress(user.address);<br>    setOccupation(user.occupation);<br>    setId(user.id);<br>  }  async function deleteUser(id) {<br>    await axios.delete(&#39;http://localhost:8081/api/users/&#39; + id);<br>    alert(&#39;User deleted Successfully&#39;);<br>    Load();<br>  }  async function update(event) {<br>    event.preventDefault();<br>    try {<br>      await axios.put(&#39;http://localhost:8081/api/users/&#39; + id, {<br>        firstName: firstName,<br>        lastName: lastName,<br>        address: address,<br>        occupation: occupation,<br>      });<br>      alert(&#39;Registration Updated&#39;);<br>      setId(&#39;&#39;);<br>      setFirstName(&#39;&#39;);<br>      setLastName(&#39;&#39;);<br>      setAddress(&#39;&#39;);<br>      setOccupation(&#39;&#39;);<br>      Load();<br>    } catch (err) {<br>      alert(&#39;User Update Failed&#39;);<br>    }<br>  }  return (<br>    &lt;div&gt;<br>      &lt;h1&gt;<br>        &lt;center&gt;User Management System&lt;/center&gt;<br>      &lt;/h1&gt;<br>      &lt;div className=&quot;container mt-4&quot;&gt;<br>        &lt;form&gt;<br>          &lt;div className=&quot;form-group&quot;&gt;<br>            &lt;label&gt;First Name&lt;/label&gt;<br>            &lt;input<br>              type=&quot;text&quot;<br>              className=&quot;form-control&quot;<br>              value={firstName}<br>              onChange={(event) =&gt; {<br>                setFirstName(event.target.value);<br>              }}<br>            /&gt;<br>          &lt;/div&gt;          &lt;div className=&quot;form-group&quot;&gt;<br>            &lt;label&gt;Last Name&lt;/label&gt;<br>            &lt;input<br>              type=&quot;text&quot;<br>              className=&quot;form-control&quot;<br>              value={lastName}<br>              onChange={(event) =&gt; {<br>                setLastName(event.target.value);<br>              }}<br>            /&gt;<br>          &lt;/div&gt;          &lt;div className=&quot;form-group&quot;&gt;<br>            &lt;label&gt;Address&lt;/label&gt;<br>            &lt;input<br>              type=&quot;text&quot;<br>              className=&quot;form-control&quot;<br>              value={address}<br>              onChange={(event) =&gt; {<br>                setAddress(event.target.value);<br>              }}<br>            /&gt;<br>          &lt;/div&gt;          &lt;div className=&quot;form-group&quot;&gt;<br>            &lt;label&gt;Occupation&lt;/label&gt;<br>            &lt;input<br>              type=&quot;text&quot;<br>              className=&quot;form-control&quot;<br>              value={occupation}<br>              onChange={(event) =&gt; {<br>                setOccupation(event.target.value);<br>              }}<br>            /&gt;<br>          &lt;/div&gt;          &lt;div&gt;<br>            &lt;button className=&quot;btn btn-primary mt-4&quot; onClick={save}&gt;<br>              Register<br>            &lt;/button&gt;            &lt;button className=&quot;btn btn-warning mt-4&quot; onClick={update}&gt;<br>              Update<br>            &lt;/button&gt;<br>          &lt;/div&gt;<br>        &lt;/form&gt;        &lt;br /&gt;<br>        &lt;table className=&quot;table table-dark&quot; align=&quot;center&quot;&gt;<br>          &lt;thead&gt;<br>            &lt;tr&gt;<br>              &lt;th scope=&quot;col&quot;&gt;First Name&lt;/th&gt;<br>              &lt;th scope=&quot;col&quot;&gt;Last Name&lt;/th&gt;<br>              &lt;th scope=&quot;col&quot;&gt;Address&lt;/th&gt;<br>              &lt;th scope=&quot;col&quot;&gt;Occupation&lt;/th&gt;<br>              &lt;th scope=&quot;col&quot;&gt;Option&lt;/th&gt;<br>            &lt;/tr&gt;<br>          &lt;/thead&gt;<br>          &lt;tbody&gt;<br>            {users.map((user) =&gt; (<br>              &lt;tr key={user.id}&gt;<br>                &lt;td&gt;{user.firstName}&lt;/td&gt;<br>                &lt;td&gt;{user.lastName}&lt;/td&gt;<br>                &lt;td&gt;{user.address}&lt;/td&gt;<br>                &lt;td&gt;{user.occupation}&lt;/td&gt;<br>                &lt;td&gt;<br>                  &lt;button<br>                    type=&quot;button&quot;<br>                    className=&quot;btn btn-warning&quot;<br>                    onClick={() =&gt; editUser(user)}<br>                  &gt;<br>                    Edit<br>                  &lt;/button&gt;<br>                  &lt;button<br>                    type=&quot;button&quot;<br>                    className=&quot;btn btn-danger&quot;<br>                    onClick={() =&gt; deleteUser(user.id)}<br>                  &gt;<br>                    Delete<br>                  &lt;/button&gt;<br>                &lt;/td&gt;<br>              &lt;/tr&gt;<br>            ))}<br>          &lt;/tbody&gt;<br>        &lt;/table&gt;<br>      &lt;/div&gt;<br>    &lt;/div&gt;<br>  );<br>}export default User;</pre><p>Explanation:</p><ol><li>State Variables: The component uses the useState hook to manage state variables. For example, firstName, lastName, address, occupation, id, and users are all state variables.</li><li>useEffect: The useEffect hook is used to load data when the component mounts. It makes an API call to the backend (http://localhost:8081/api/users) using Axios and sets the fetched data to the users state variable.</li><li>Form Inputs: The component displays a form with input fields for entering the user details (First Name, Last Name, Address, and Occupation). The values of these input fields are controlled by the state variables firstName, lastName, address, and occupation.</li><li>Event Handlers: The component defines event handler functions like save, editUser, deleteUser, and update. These functions are responsible for performing actions like saving a new user, updating user information, and deleting users.</li><li>Axios Requests: Axios is used to make HTTP requests to the Spring Boot backend. It sends POST, PUT, and DELETE requests to create, update, and delete users, respectively.</li><li>Rendering Users Table: The component renders a table to display the list of users fetched from the backend. It maps through the users state variable and renders each user&#39;s details (First Name, Last Name, Address, and Occupation) in a table row. The table also has buttons to edit or delete a user.</li><li>Button Click Actions: When the “Register” button is clicked, the save function is called to add a new user. When the &quot;Update&quot; button is clicked, the update function is called to update the user information. When the &quot;Edit&quot; button is clicked for a user, the editUser function is called to populate the input fields with the user&#39;s data. When the &quot;Delete&quot; button is clicked for a user, the deleteUser function is called to delete that user.</li><li>Alerts: The component uses alert to show success or failure messages when user registration, update, or delete operations are performed.</li></ol><p><strong>Step 3: <em>Export user package &amp; import to user.jsx</em></strong></p><p>add this code there</p><pre>import User from &quot;./components/user&quot;;<br></pre><pre>function App() {<br>  return (<br>    &lt;div&gt;<br>      &lt;User/&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><pre>export default App;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*nToltCVTAW_-w8Lo.png" /></figure><p><strong>Step 4: <em>Test the Application</em></strong></p><p>Run the React development server to test your application:</p><pre>npm start</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*1u71YpB45ur-Rouk.png" /></figure><p>Open your web browser and navigate to <a href="http://localhost:3000/">http://localhost:3000</a>. You should see your React application with the user management system.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*1tCA-9MtBvDjaB_H.jpeg" /></figure><p><em>After registering. Press okay to view new user registered details</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*myjJaChcse6uKWPG.png" /></figure><p><em>After updating. press okay to view updated profile below</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*qsF4OeVZnbijXJQp.png" /></figure><p><em>After deleting. press okay which next the record will be deleted</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*qxR_V-8b6_r6wDIF.png" /></figure><p>Test the user management system by viewing user data, creating new users, updating user information, and deleting users. Verify if these operations are properly</p><p><strong>Github repository link:</strong> <a href="https://github.com/rosnifarook/user-management-system-springBoot-react-mongoDb.git">https://github.com/rosnifarook/user-management-system-springBoot-react-mongoDb.git</a></p><p><strong>Presentation video link: </strong><a href="https://drive.google.com/drive/folders/1OtaBNkbRSc0TK3rXhmna0w5t7LxcHvY0?usp=sharing">https://drive.google.com/drive/folders/1OtaBNkbRSc0TK3rXhmna0w5t7LxcHvY0?usp=sharing</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=164d85a7bbf9" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>