<?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 Arvind Narayan on Medium]]></title>
        <description><![CDATA[Stories by Arvind Narayan on Medium]]></description>
        <link>https://medium.com/@thearvindnarayan?source=rss-8fddfbb38b7a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*VjHQX6ZihhPqzz2jOIfrvw.jpeg</url>
            <title>Stories by Arvind Narayan on Medium</title>
            <link>https://medium.com/@thearvindnarayan?source=rss-8fddfbb38b7a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 10:11:36 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@thearvindnarayan/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[How we improved user experience by building a lite version of the upGrad learner platform]]></title>
            <link>https://medium.com/technology-at-upgrad/how-we-improved-user-experience-by-building-a-lite-version-of-learner-experience-ui-2df5ee521a5f?source=rss-8fddfbb38b7a------2</link>
            <guid isPermaLink="false">https://medium.com/p/2df5ee521a5f</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[lighthouse]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[performance]]></category>
            <category><![CDATA[web]]></category>
            <dc:creator><![CDATA[Arvind Narayan]]></dc:creator>
            <pubDate>Thu, 07 Jan 2021 05:43:53 GMT</pubDate>
            <atom:updated>2021-05-03T08:14:14.112Z</atom:updated>
            <content:encoded><![CDATA[<h3>How we improved user experience with a lite version of the upGrad’s learning platform</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5Y-dPR3IkBOOjVpb7Nkngw.png" /></figure><h3>Preface</h3><p><strong>Problem Statement: <br></strong>Many of upGrad’s users in India do not have access to powerful devices or high bandwidth internet, which affects their browsing experience. upGrad learners with poor or unstable bandwidth connections or with low-end devices had reported issues with screen loading times and general responsiveness of the User Interface (UI).</p><p>This was an important problem for us to resolve as providing a smooth and seamless learning experience to all our users is a key goal for upGrad.</p><p>The upGrad <strong>learner platform </strong>UI was written in <a href="https://backbonejs.org/">Backbone.js</a> a few years ago, was heavy in size, lacked re-render performance, and was difficult to maintain and enhance. In order to solve the problem, we decided to revamp our architecture with a modern rewrite and build a lighter version of the platform — <a href="https://lite.upgrad.com/">upGrad Learn Lite</a> — which is much more forgiving of poor bandwidth and devices.</p><h3>The outcome</h3><ol><li><strong>Lighthouse Scores:</strong></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FvddA0zP7zitgHqDfZw4eg.png" /><figcaption>Lighthouse comparison of old and new platform</figcaption></figure><p>As a result of the exercise, we increased the <strong>Lighthouse</strong> score from a marginal <strong>1</strong> to a staggering <strong>92</strong> on the home page of the application. In addition to improving the load times, we also converted the app to an easily extensible Progressive Web App (PWA).</p><p>2.<strong> Load time improvements</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cuuxc5OlX0OOnG-rsY-z9A.png" /><figcaption>Load time comparisons</figcaption></figure><p>As you can see from the above image the <strong>legacy</strong> <strong>learner platform </strong>was heavy with 13.4 MB as the size of requests and takes 6.6s to load. The <strong>Learn Lite platform </strong>is 3.4 MB in size and takes 3s to load entirely. The best part is once the New App is loaded all the bundles and assets are cached the request size is just 1.7MB!</p><p>Where this improvement shines is in low bandwidth situations. The application provides faster initial loads and mimics the experience of an app where most static assets such as bundled CSS and JS files along with fonts, images, and icons are cashed and only API calls are required to fetch data.</p><p>3. <strong>Interactive Performance</strong>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VgCRT2o0klLnPbNWldvztw.png" /><figcaption>Interactive performance comparisons</figcaption></figure><p>As you can see there is a significant drop in <strong>scripting</strong> and <strong>loading</strong> times (by a factor of 5). The user experience of the new app is noticeably better; every interaction is slick and smooth and re-rendering is low due to usage of <a href="https://reactjs.org/">Reactjs</a> and thanks to <a href="https://reactjs.org/docs/reconciliation.html">React’s Virtual DOM</a> Reconciliation.</p><p>The rest of this blog describes technical details of the revamp (project codename Ares) of the legacy platform.</p><h3>How we did it</h3><p>First and foremost, the technology behind the entire Revamp (project code name — Ares)</p><p><strong>Frontend:</strong></p><ul><li><a href="https://github.com/facebook/react">React</a></li><li><a href="https://github.com/ReactTraining/react-router">React router</a> in conjunction with <a href="https://github.com/supasate/connected-react-router">Connected React Router</a></li><li><a href="https://react-redux.js.org/">React Redux</a> along with <a href="https://redux-toolkit.js.org/">Redux Toolkit</a></li><li><a href="https://reactjs.org/docs/create-a-new-react-app.html">CRA (Create React App)</a></li><li><a href="https://github.com/axios/axios">Axios</a> for HTTP AJAX</li><li><a href="https://github.com/GoogleChrome/sw-toolbox">sw-toolbox</a> (comes with CRA)</li></ul><p><strong>Tooling</strong></p><ul><li><a href="https://github.com/postcss/postcss">Postcss</a> (+ autoprefixer, cssnext).</li><li><a href="http://babeljs.io/">Babel</a></li><li><a href="https://webpack.github.io/">Webpack</a></li><li><a href="http://www.html5rocks.com/en/tutorials/service-worker/introduction/">Service Workers</a></li></ul><p><strong>Infrastructure</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s2jnULRf2RgDWDtTsV5ZJA.png" /><figcaption>Infrastructure based on Client View</figcaption></figure><p>Our architecture is plain simple and gets the job done. The application gets compiled and uploaded to <a href="https://aws.amazon.com/s3/">AWS S3</a> after deleting the old build via our CI/CD Pipeline (<a href="https://www.jenkins.io/">Jenkins</a>) and is delivered across geographies with the help of <a href="https://aws.amazon.com/cloudfront">AWS Cloudfront</a> CDN. For every release old cache gets purged.</p><p><em>The index.html file is never cached. This is intentional as any new updates are routed via new index.html</em></p><p>We use <a href="https://imagekit.io/">Imagekit</a> (Image CDN with automatic optimization) for delivery of Images</p><blockquote>Having no intermittent server reduced the Infrastructure Complexity and Increased the scalability whilst also drastically improving the Web App Delivery. 🚚</blockquote><h3><strong>The Code</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*2afuvL4rV_VIdrta.png" /></figure><p>Now, let us deep-dive into React and general frontend principles talking about the changes we have done. Usage of React and its ecosystem by itself was a huge factor in boosting the app&#39;s performance.</p><h4><strong>Lazy Loading</strong></h4><p>Lazy Loading is a feature that enables you to load certain other bundles after some user interaction like changing the route. This means that you can chop your huge application into segments with some performance budgeting to meet your needs.<br>This will drastically reduce the initial load size of the App and load the application as per the User&#39;s usage of modules.</p><pre>import React, { Suspense } from &#39;react&#39;;</pre><pre>Import FirstComponent from &#39;./FirstComponent&#39;;<br>const OtherComponent = React.lazy(() =&gt; import(&#39;./OtherComponent&#39;));<br><br>function MyComponent() {<br>  return (<br>    &lt;div&gt;<br>      &lt;Suspense fallback={&lt;div&gt;Loading...&lt;/div&gt;}&gt;<br>        &lt;Switch&gt;<br>         &lt;Route to=&quot;/&quot;&gt; &lt;FirstComponent /&gt; &lt;/Route&gt;<br>         &lt;Route to=&quot;/lazy-route&quot;&gt; &lt;OtherComponent /&gt; &lt;/Route&gt;<br>        &lt;/Switch&gt;<br>      &lt;/Suspense&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><p>With help of React.lazy you can lazy load certain components We’ve had to lazy load the main module routes to fit into our performance budgets (less than 500kb). <strong>Suspense</strong> is a React component that would render some placeholder until the lazy-loaded component is fetched. You can have a placeholder component(loader, image and etc.,) in the fallback prop until the new bundle is loaded.</p><pre>import React from &#39;react&#39;;<br>import { somefunction } from &#39;someLib&#39;;</pre><pre>function MyComponent() {<br>  <br>  const lazyFun = () =&gt; {<br>    import(&#39;lazy-lib&#39;).then((lazyLibraryFunction) =&gt; {<br>     lazyLibraryFunction();<br>   });<br>  };<br>  <br>  <br>  return (<br>    &lt;div&gt;<br>     &lt;button onClick={() =&gt; lazyFun()}&gt; Click to lazy execute   <br>     &lt;/button&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><p>Not only did we lazy load components and routes but we have gone a step further to lazy load certain libraries that are only used conditionally.</p><pre>export const changeLanguage = (locale) =&gt; (dispatch) =&gt; {</pre><pre> import(`../locale/${locale}.json`).then(({ default: language }) =&gt;{ <br>    dispatch({<br>             type: &#39;SET_LANGUAGE&#39;,<br>             language,<br>             locale,<br>             });<br>  }).catch(() =&gt; {});</pre><pre>};<br></pre><p>We are also lazy-loaded certain static JSON optionally. Like the example above where we lazy load the language JSON as per locale selected. This way the language files that were loaded were of the user’s choosing.</p><h4><strong>Usage of React Hooks:</strong></h4><p><strong><em>React</em> <em>Hooks</em> </strong>are a new addition in React 16.8 and they are certainly for the best. You can write pure <strong>Functional components</strong> and still manage to use <strong>State </strong>and<strong> Lifecycle </strong>via hooks courtesy of <strong>useState</strong> and <strong>useEffect</strong>. You might be pondering upon how the usage of hooks in functional components adds benefit with respect to performance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/0*0EFTNseQ_f0zpWK4.gif" /><figcaption>Class-based component to JS (ES 2015)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/0*_GfZ4gZ3STL8go_5.gif" /><figcaption>Functional component to JS (ES 2015)</figcaption></figure><p>As you can see from the above Gifs functional components have nearly half the footprint of Class-based components simply due to the complexity of emulating classes and it’s a feature in JS as functions. This end of the day results in much smaller bundles.</p><p>This also means using Hooks from other libraries like <a href="https://reactrouter.com/web/api/Hooks">React Router </a>and <a href="https://react-redux.js.org/api/hooks">React Redux</a> wherever support is provided. At this point, everybody has moved to hooks or at least support it.</p><h4><strong>React memo:</strong></h4><p>When deciding to update DOM, React first renders your component, then compares the result with the previous render result. If the render results are different, React updates the DOM.</p><p>Current vs previous render results comparison is fast. But you can <em>speed up</em> the process under some circumstances.</p><p>When a component is wrapped in React.memo(), React renders the component and memoizes the result. Before the next render, if the new props are the same, React reuses the memoized result <em>skipping the next render</em>.</p><pre>export function MemoComp({ prop1, prop2 }) {<br>  return (<br>    &lt;div&gt;<br>      &lt;div&gt;Property 1 : {prop1}&lt;/div&gt;<br>      &lt;div&gt;Property 2: {prop2}&lt;/div&gt;<br>    &lt;/div&gt;<br>  );<br>}<br><br>export const MemoizedComp = React.memo(MemoComp);</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GjFaeLCbv-QIQq31SbarPQ.png" /><figcaption>Courtesy of <a href="https://dmitripavlutin.com/"><strong>Dmitri Pavlutin</strong></a></figcaption></figure><h4><strong>Avoiding Reconciliation:</strong></h4><p>This basically means to avoid unwanted re-renders. Here are a few things you might have to give a thought about.</p><ol><li>Usage of React.memo as shown above, dramatically reduces re-renders.</li><li>Subscribe to only used sections of the global store. Subscribing to a larger section opens up possibilities of unwanted re-renders caused by other state changes.</li><li>Dispatch One Action for One Reducer that is if you are changing the Redux State at any given point maintain 1–1 ratio of action to dispatch. The below example dispatching two actions to the same reducer triggers one extra unwanted Rerender. This is for one simple API Action but as and when the application grows a lot of these things go unnoticed.</li></ol><pre>const ActionGenerator = () =&gt; dispatch =&gt; {<br> dispatch(ON_LOADER);<br> api().then((data) =&gt; { <br>  dispatch(OFF_LOADER)<br>  dispatch(SET_DATA, data)<br> })</pre><pre>}</pre><pre>// This causes 2 updates to store and 2*componenets times Rerenders </pre><p>What if you have to dispatch multiple actions or you have to update two sub-states. You can use Redux Batch to speed to do this. batch API allows any React updates in an event loop tick to be batched together into a single render pass.</p><pre>import { batch } from &#39;react-redux&#39;</pre><pre>const myThunk = () =&gt; (dispatch, getState) =&gt; {<br> // should only result in one combined re-render, not two<br> batch(() =&gt; {<br>  dispatch(increment())<br>  dispatch(increment())<br> })<br>}</pre><h4>Avoiding Usage of Large Libraries:</h4><p>There are certain libraries like <a href="https://momentjs.com/">Moment</a>, <a href="https://lodash.com/">Loadash</a>, etc., that huge packages without the support of <a href="https://webpack.js.org/guides/tree-shaking/">Tree Shaking</a> (<em>Tree shaking</em> is a term commonly used in the JavaScript context for unused code elimination). These libraries increase the time for the initial load. Take a look below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lDWiqFxAfUhMehQ4mwM94Q.png" /><figcaption>Moment JS bundle stats</figcaption></figure><p>A good alternative to Moment would be <a href="https://github.com/date-fns/date-fns">date-fns</a> (18kb)or <a href="https://github.com/iamkun/dayjs">DayJS</a> (2kb) day js has fewer features in comparison with date-fns. For lodash we started writing our own utils inspired by lodash.</p><p>We wrote most of our components from scratch without using any UI Framework like <a href="https://ant.design/"><strong>antd</strong></a><strong> </strong>thus reaping the benefits of performance.</p><p><em>📝On a side note, Ant Design is one of the most feature-packed React Libraries out there. Solves most of your problems with less development time and effort.</em></p><h4>Optimizing CSS and Assets</h4><p>As mentioned in the above point we build our own UI Components likewise we refrained from using popular CSS libraries like <a href="https://getbootstrap.com/">Bootstrap</a>, <a href="https://bulma.io/">Bulma</a>, etc., this means CSS contains only styles we used and not any other fluff.</p><p><a href="https://purgecss.com/"><strong>Purging CSS</strong></a><strong>: </strong>This is a tool that removes unused CSS. This is especially useful if you are using any CSS Library (we did not have to) it just removes all unwanted styles.</p><p><strong>SVG Components for all our assets: </strong>All the Design assets like Icons, Illustrations, Badges, etc., apart from Few Images were exported as SVG’s and used as React Components show below.</p><pre>// Component <br>import React from &#39;react&#39;;<br>import SvgWrapper from &#39;.&#39;;</pre><pre>const AssetsExample = props =&gt; (<br> &lt;SvgWrapper {...props}&gt;<br>  &lt;path&gt;&lt;/path&gt;<br>  // other SVG markup  <br> &lt;/SvgWrapper&gt;<br>);</pre><pre>// Usage</pre><pre>...<br>&lt;AssetsExample fill=&quot;#555555&quot; width={x} /&gt;<br>...</pre><p>The benefit of this is that all our assets are treated as JS files. They are compiled and minified along with other JS which makes it much lighter. Elsewise you would have to load SVG’s as Images even via a CDN.</p><h3>Lighthouse specific enhancements</h3><p><a href="https://developers.google.com/web/tools/lighthouse">Lighthouse</a> is an Industry standard for web performance. The criteria for scoring in Performance as of lighthouse 6.0 by order of weightage is <a href="https://web.dev/lcp/">Largest Contentful Paint</a>, <a href="https://web.dev/lighthouse-total-blocking-time/">Total Blocking Time</a>, <a href="https://web.dev/first-contentful-paint/">First Contentful Paint</a>, <a href="https://web.dev/speed-index/">Speed Index</a>, <a href="https://web.dev/interactive/">Time to Interactive</a> and <a href="https://web.dev/cls/">Cumulative Layout Shift</a>.</p><p>We targeted to maximize the top four criteria which contribute to 80% of the lighthouse score. As that is where most of our business impact is seen.</p><p><strong>Largest Contentful Paint — LCP [25%]</strong> LCP essentially means time taken to render out the largest image or text field visible within the viewport.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/890/1*GKEkTtA9RJzAhiDgHJrGtw.png" /></figure><p>elements that are considered <em>&lt;img&gt;, &lt;image&gt;, &lt;video&gt;</em>,An element with a background image loaded via the <em>url()</em> and Block elements with text or inline elements.</p><p>The size of the element reported for Largest Contentful Paint is typically the size that’s visible to the user within the viewport. If the element extends outside of the viewport, or if any of the element is clipped or has non-visible <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/overflow">overflow</a>, those portions do not count toward the element’s size.</p><p>For image elements that have been resized from their <a href="https://developer.mozilla.org/en-US/docs/Glossary/Intrinsic_Size">intrinsic size</a>, the size that gets reported is either the visible size or the intrinsic size, whichever is smaller. For example, images that are shrunk down to a much smaller than their intrinsic size will only report the size they’re displayed at, whereas images that are stretched or expanded to a larger size will only report their intrinsic sizes.</p><p>For text elements, only the size of their text nodes is considered (the smallest rectangle that encompasses all text nodes).</p><p>For all elements, any margin, padding, or border applied via CSS is not considered.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sNfHIWjS0370XKIY_4ZPYw.png" /><figcaption>credits: web.dev by google</figcaption></figure><p><strong>What we did</strong> was to introduce the use of Skeleton Loader with Shimmer Animation via `background-image: URL(&lt;imageUrl&gt;)` before even making the API call to fetch the data. Once the data is fetched we replace the skeleton loader with the actual UI.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R-8AtDMq6VDPLkzdWdl_yw.png" /><figcaption>Old vs New app loading</figcaption></figure><p>This is a better way of communicating to the user what interface to expect as early as possible in the loading process. As they outline the structure itself, they can be hardcoded to appear while the server is still collecting and delivering all the page-specific content. Additionally, the user is provided with a sense of progression as the blank screen fills in with the skeleton and then the content, instead of just staring at a loading spinner or blank screen until the content is rendered.</p><p><strong>Total Blocking Time-TBT [25%]: </strong>TBT is the minimum wait time required by the user to use the application as in trigger events, such as mouse clicks, screen taps, or keyboard presses. The sum is calculated by adding the <em>blocking portion</em> of all <a href="https://web.dev/long-tasks-devtools">long tasks</a> between <a href="https://web.dev/first-contentful-paint/">First Contentful Paint</a> and <a href="https://web.dev/interactive/">Time to Interactive</a>. Any task that executes for more than 50 ms is a long task. The amount of time after 50 ms is the blocking portion. For example, if Lighthouse detects a 70 ms long task, the blocking portion would be 20 ms.</p><p>We did not actually do anything specifically to boost the TBT score. But I shall explain things that might push down TBT scores.</p><p>Loading, parsing, or execution js(javascript) impacts the time required for users to start interacting hence reducing bundle sizes by methods mentioned above like Lazy-Loading, Usage of Hooks and Nonusage of huge libraries reduces our bundle size which in turn reduced amount of js that has to be processed.</p><p><strong>FCP: </strong>The First Contentful Paint (FCP) metric measures the time from when the page starts loading to when any part of the page’s content is rendered on the screen. These contents might be Images, SVG elements, Text elements, and white canvas.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*FvqBbuRTWGRI7H_u.png" /><figcaption>credits: web.dev by google</figcaption></figure><p><strong>What we did:</strong> In a SPA(Single Page application) you would have a <strong><em>Root </em></strong>div element and your entire app would mount on inside that element. like the snippet below.</p><pre>&lt;body&gt;</pre><pre> &lt;div <em>id</em>=&quot;app&quot;&gt;&lt;/div&gt;</pre><pre>&lt;/body&gt;<br>...</pre><p>Without the loader in the html file.</p><pre>...<br>&lt;body&gt;</pre><pre>&lt;div <em>id</em>=&quot;app&quot;&gt;</pre><pre> &lt;div <em>id</em>=&quot;pageLoaderRoot&quot; <em>class</em>=&quot;loaderRoot&quot;&gt;<br>  &lt;img <em>class</em>=&quot;spinnerImage&quot; <em>src</em>=&quot;/path/to/loaderImg&quot;<br>   <em>alt</em>=&quot;Loading...&quot; /&gt;<br>  &lt;div <em>class</em>=&quot;barSpinner&quot;&gt;&lt;/div&gt;<br> &lt;/div&gt;</pre><pre>&lt;/div&gt;</pre><pre>&lt;/body&gt;<br>...</pre><p>With the loader inside the HTML file</p><p>Here we have placed a loader in form of an image inside <strong>Root Div</strong> with this the HTML file will load the loader first and later our JS bundles would override contents inside the div with our Application.</p><p>By adding the loader like this as soon as the index.html file is loaded the loader spinner is rendered ASAP. This by principle would boost FCP scores by a good margin.</p><p><strong>Speed Index:</strong> Speed Index measures how quickly content is visually displayed during page load. Lighthouse basically captures a video of the web page loading and calculates the visual difference between each frame.</p><p><strong>What we did:</strong></p><ol><li>Font Visibility: The easiest way to avoid showing invisible text while custom fonts load is to temporarily show a system font. By including font-display: swap in your @font-face style, you can avoid FOIT in most modern browsers</li><li>Preloading Key Requests: We preloaded all our fonts, CSS, and certain JS files via <a href="https://github.com/webpack/webpack">Webpack</a> and use of <a href="https://github.com/GoogleChromeLabs/preload-webpack-plugin">preload-webpack-plugin</a>. By doing this all our crucial resources required throughout the app are pre-loaded in a non-blocking manner.</li><li>Pre connecting to CDN and other tools: The preconnect directive allows the browser to <strong>setup early connections before an HTTP request is actually sent to the server</strong>. This includes DNS lookups, TLS negotiations, TCP handshakes. This in turn eliminates roundtrip latency and saves time for resolving used resources.</li><li>Purge CSS: <a href="https://purgecss.com/">PurgeCSS</a> is a tool to remove unused CSS. If you are using any third-party library or using your library for styling changes are that they are huge and you are not really using all the selectors. Purge CSS would scan all your selectors and remove all unused CSS that does not have a selector used.</li></ol><h3><strong>Epilogue</strong></h3><p>This blog is our story of how we achieved good web performance for a React JS based Single Page Application using standard SCSS. There are certain applications and processes like usage of CSS in JS or using Server Side Rendered(SSR) application that might differ in certain cases from the above.</p><p>The need to build fast applications came in as a necessity but the knowledge was my <strong>Life Long Learning</strong> from past experiences. Likewise, my work at <a href="https://www.upgrad.com/about/"><strong>upGrad</strong></a><strong> </strong>is now only about building applications but also to build a platform that <strong>empowers</strong> a ton of folks and helps build the <strong>Careers of Tomorrow</strong>. Do visit <a href="https://www.upgrad.com/"><strong>upGrad.com</strong></a> to check out our programs that are completely online! If you wish to work with our ever-enthusiastic team, check out <a href="https://www.upgrad.com/open-positions"><strong>our careers page</strong></a><strong>.</strong> We are always on the lookout for ambitious, talented folks!</p><p>If this blog was helpful do clap as much as possible and let us know in the comments how it helped you. If you feel anything amiss and there is more to it, Please drop in your comments we are more than happy to engage with your discussion.</p><p><strong>Resources</strong></p><p><a href="https://reactjs.org/docs/optimizing-performance.html">https://reactjs.org/docs/optimizing-performance.html</a> — React Specific optimizations.</p><p><a href="https://ui.dev/why-react-hooks/">https://ui.dev/why-react-hooks/</a> — React hooks why ?</p><p><a href="https://web.dev/performance-scoring/">https://web.dev/performance-scoring/</a> — Lighthouse scoring deep dive.</p><p><a href="https://dmitripavlutin.com/use-react-memo-wisely/">https://dmitripavlutin.com/use-react-memo-wisely/</a> — React Memo deep dive</p><p><a href="https://developers.google.com/web/tools/workbox/guides/configure-workbox">https://developers.google.com/web/tools/workbox/guides/configure-workbox</a> — workbox configuration deep dive</p><p><a href="https://medium.com/@joecrobak/production-deploy-of-a-single-page-app-using-s3-and-cloudfront-d4aa2d170aa3">https://medium.com/@joecrobak/production-deploy-of-a-single-page-app-using-s3-and-cloudfront-d4aa2d170aa3</a> — S3 deployment made easy</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2df5ee521a5f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/technology-at-upgrad/how-we-improved-user-experience-by-building-a-lite-version-of-learner-experience-ui-2df5ee521a5f">How we improved user experience by building a lite version of the upGrad learner platform</a> was originally published in <a href="https://medium.com/technology-at-upgrad">Technology at upGrad</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Role Based Access Control (RBAC) ? ‍♂️⚠️]]></title>
            <link>https://medium.com/technology-at-upgrad/how-to-role-based-access-control-9294146dc6e3?source=rss-8fddfbb38b7a------2</link>
            <guid isPermaLink="false">https://medium.com/p/9294146dc6e3</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[rbac]]></category>
            <category><![CDATA[node]]></category>
            <category><![CDATA[upgrad]]></category>
            <dc:creator><![CDATA[Arvind Narayan]]></dc:creator>
            <pubDate>Wed, 27 May 2020 06:39:22 GMT</pubDate>
            <atom:updated>2020-06-04T10:51:03.682Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to Role Based Access Control (RBAC) ? 👮‍♂️⚠️</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/620/1*FODCuSopkLYNBCFcFf6t_g.jpeg" /><figcaption>like seriously some people ask me this</figcaption></figure><blockquote><strong>NOTE: </strong>For the sake of simplicity this article is going to be based on <a href="http://react.com/">React JS</a> along with <a href="https://github.com/ReactTraining/react-router">React Router</a> and <a href="https://nodejs.org/">Node JS </a>on <a href="https://expressjs.com/">Express JS</a> for backend, all of which are awesome and do check them out.</blockquote><p>Have you ever wondered how in the world certain large scale applications like <a href="http://airbnb.com/">airbnb</a>, <a href="http://facebook.com/">facebook</a>, <a href="http://youtube.com/">youtube</a> etc., manages to block a certain part of their application for certain people or release features based on certain conditions ? They all use a tried and tested methodology called RBAC this solution gained traction during the 90’s and still is widely used in a lot of forms. RBAC stands for Role Based Access Control as the title says and this article helps you fathom the RBAC game.</p><h3>Parameters to considers for RBAC :-</h3><h3><strong>1. Route Guarding </strong>🛣️:</h3><p>This is a process of authenticating 🔒 and authorising routes or part of a url in your web app. Typically you have a router switch with route paths couple. Here you can see that the routes stay in a different file to act as s single source of truth. In the switch instead of routes we wrap it with a wrapper and pass roles required path and component to be rendered as props.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%3Fbg%3Drgba%28248%252C231%252C28%252C1%29%26t%3Dsynthwave-84%26wt%3Dnone%26l%3Dauto%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D56px%26ph%3D56px%26ln%3Dfalse%26fl%3D1%26fm%3DHack%26fs%3D14px%26lh%3D133%2525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3Dmodule.exports%252520%25253D%252520%25257B%25250A%252509homePage%25253A%252520%25257B%25250A%252509%252509route%25253A%252520%2527%25252F%2527%25252C%25250A%252509%252509roles%25253A%252520%25255B%2527ROLE_TEACHER%2527%25252C%252520%2527ROLE_ADMIN%2527%25252C%252520%2527ROLE_EXTERNAL_SOURCER%2527%25255D%25250A%252509%25257D%25252C%25250A%252509createQuestion%25253A%252520%25257B%25250A%252509%252509route%25253A%252520%2527%25252Fquestion-bank%25252Fcreate%25252F%25253Atype%25252F%2527%25252C%25250A%252509%252509roles%25253A%252520%25255B%2527ROLE_TEACHER%2527%25252C%252520%2527ROLE_ADMIN%2527%25252C%252520%2527ROLE_EXTERNAL_SOURCER%2527%25255D%25250A%252509%25257D%25252C%25250A%252509testAttempt%25253A%252520%25257B%25250A%252509%252509route%25253A%252520%2527%25252Fstudent%25252Ftest%25252F%25253Agid%2527%25252C%25250A%252509%252509roles%25253A%252520%25255B%2527ROLE_TEACHER%2527%25252C%252520%2527ROLE_ADMIN%2527%25252C%252520%2527ROLE_STUDENT%2527%25255D%25250A%252509%25257D%25250A%25257D%25253B&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2F%3Fbg%3Drgba%28248%25252C231%25252C28%25252C1%29%26t%3Dsynthwave-84%26wt%3Dnone%26l%3Dauto%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D56px%26ph%3D56px%26ln%3Dfalse%26fl%3D1%26fm%3DHack%26fs%3D14px%26lh%3D133%252525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3Dmodule.exports%25252520%2525253D%25252520%2525257B%2525250A%25252509homePage%2525253A%25252520%2525257B%2525250A%25252509%25252509route%2525253A%25252520%27%2525252F%27%2525252C%2525250A%25252509%25252509roles%2525253A%25252520%2525255B%27ROLE_TEACHER%27%2525252C%25252520%27ROLE_ADMIN%27%2525252C%25252520%27ROLE_EXTERNAL_SOURCER%27%2525255D%2525250A%25252509%2525257D%2525252C%2525250A%25252509createQuestion%2525253A%25252520%2525257B%2525250A%25252509%25252509route%2525253A%25252520%27%2525252Fquestion-bank%2525252Fcreate%2525252F%2525253Atype%2525252F%27%2525252C%2525250A%25252509%25252509roles%2525253A%25252520%2525255B%27ROLE_TEACHER%27%2525252C%25252520%27ROLE_ADMIN%27%2525252C%25252520%27ROLE_EXTERNAL_SOURCER%27%2525255D%2525250A%25252509%2525257D%2525252C%2525250A%25252509testAttempt%2525253A%25252520%2525257B%2525250A%25252509%25252509route%2525253A%25252520%27%2525252Fstudent%2525252Ftest%2525252F%2525253Agid%27%2525252C%2525250A%25252509%25252509roles%2525253A%25252520%2525255B%27ROLE_TEACHER%27%2525252C%25252520%27ROLE_ADMIN%27%2525252C%25252520%27ROLE_STUDENT%27%2525255D%2525250A%25252509%2525257D%2525250A%2525257D%2525253B&amp;image=https%3A%2F%2Fcarbon.now.sh%2Fstatic%2Fbrand%2Fbanner.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/087d1d9433292ee3d4be959bb76eb4dd/href">https://medium.com/media/087d1d9433292ee3d4be959bb76eb4dd/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%3Fbg%3Drgba%2874%252C144%252C226%252C1%29%26t%3Dmaterial%26wt%3Dnone%26l%3Dhtmlmixed%26ds%3Dfalse%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D56px%26ph%3D56px%26ln%3Dfalse%26fl%3D1%26fm%3DFira%2520Code%26fs%3D14px%26lh%3D152%2525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3D%25253CSwitch%25253E%25250A%252520%252520%25253CRouteWrapper%25250A%252520%252520%252520%252520exact%25250A%252520%252520%252520%252520path%25253D%25257BroutePaths.homePage.route%25257D%25250A%252520%252520%252520%252520roles%25253D%25257BroutePaths.homePage.roles%25257D%25250A%252520%252520%252520%252520Component%25253D%25257BQuestionListPage%25257D%25250A%252520%252520%25252F%25253E%25250A%252520%252520%25253CRouteWrapper%25250A%252520%252520%252520%252520exact%25250A%252520%252520%252520%252520path%25253D%25257BroutePaths.createQuestion.route%25257D%25250A%252520%252520%252520%252520roles%25253D%25257BroutePaths.createQuestion.roles%25257D%25250A%252520%252520%252520%252520Component%25253D%25257BCreateQuestions%25257D%25250A%252520%252520%25252F%25253E%25250A%252520%252520%25253CRouteWrapper%25250A%252520%252520%252520%252520exact%25250A%252520%252520%252520%252520path%25253D%25257BroutePaths.testListPage.route%25257D%25250A%252520%252520%252520%252520roles%25253D%25257BroutePaths.testListPage.roles%25257D%25250A%252520%252520%252520%252520Component%25253D%25257BTestListPage%25257D%25250A%252520%252520%25252F%25253E%25250A%252520%252520%25253CRoute%252520path%25253D%252522%25252Ferror%25252F%25253Acode%252522%25253E%25250A%252520%252520%252520%252520%25253CErrorComponent%252520%25252F%25253E%25250A%252520%252520%25253C%25252FRoute%25253E%25250A%252520%252520%25253CRoute%252520path%25253D%252522%2A%252522%25253E%25250A%252520%252520%252520%252520%25253CRedirect%252520to%25253D%252522%25252Ferror%25252F404%252522%252520%25252F%25253E%25250A%252520%252520%25253C%25252FRoute%25253E%25250A%25253C%25252FSwitch%25253E%25250A&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2F%3Fbg%3Drgba%2874%25252C144%25252C226%25252C1%29%26t%3Dmaterial%26wt%3Dnone%26l%3Dhtmlmixed%26ds%3Dfalse%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D56px%26ph%3D56px%26ln%3Dfalse%26fl%3D1%26fm%3DFira%252520Code%26fs%3D14px%26lh%3D152%252525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3D%2525253CSwitch%2525253E%2525250A%25252520%25252520%2525253CRouteWrapper%2525250A%25252520%25252520%25252520%25252520exact%2525250A%25252520%25252520%25252520%25252520path%2525253D%2525257BroutePaths.homePage.route%2525257D%2525250A%25252520%25252520%25252520%25252520roles%2525253D%2525257BroutePaths.homePage.roles%2525257D%2525250A%25252520%25252520%25252520%25252520Component%2525253D%2525257BQuestionListPage%2525257D%2525250A%25252520%25252520%2525252F%2525253E%2525250A%25252520%25252520%2525253CRouteWrapper%2525250A%25252520%25252520%25252520%25252520exact%2525250A%25252520%25252520%25252520%25252520path%2525253D%2525257BroutePaths.createQuestion.route%2525257D%2525250A%25252520%25252520%25252520%25252520roles%2525253D%2525257BroutePaths.createQuestion.roles%2525257D%2525250A%25252520%25252520%25252520%25252520Component%2525253D%2525257BCreateQuestions%2525257D%2525250A%25252520%25252520%2525252F%2525253E%2525250A%25252520%25252520%2525253CRouteWrapper%2525250A%25252520%25252520%25252520%25252520exact%2525250A%25252520%25252520%25252520%25252520path%2525253D%2525257BroutePaths.testListPage.route%2525257D%2525250A%25252520%25252520%25252520%25252520roles%2525253D%2525257BroutePaths.testListPage.roles%2525257D%2525250A%25252520%25252520%25252520%25252520Component%2525253D%2525257BTestListPage%2525257D%2525250A%25252520%25252520%2525252F%2525253E%2525250A%25252520%25252520%2525253CRoute%25252520path%2525253D%25252522%2525252Ferror%2525252F%2525253Acode%25252522%2525253E%2525250A%25252520%25252520%25252520%25252520%2525253CErrorComponent%25252520%2525252F%2525253E%2525250A%25252520%25252520%2525253C%2525252FRoute%2525253E%2525250A%25252520%25252520%2525253CRoute%25252520path%2525253D%25252522%2A%25252522%2525253E%2525250A%25252520%25252520%25252520%25252520%2525253CRedirect%25252520to%2525253D%25252522%2525252Ferror%2525252F404%25252522%25252520%2525252F%2525253E%2525250A%25252520%25252520%2525253C%2525252FRoute%2525253E%2525250A%2525253C%2525252FSwitch%2525253E%2525250A&amp;image=https%3A%2F%2Fcarbon.now.sh%2Fstatic%2Fbrand%2Fbanner.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/eb237fbff1966e5996ef13bdd24f5757/href">https://medium.com/media/eb237fbff1966e5996ef13bdd24f5757/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%3Fbg%3Drgba%2833%252C7%252C46%252C1%29%26t%3Dsynthwave-84%26wt%3Dnone%26l%3Dauto%26ds%3Dfalse%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dfalse%26wa%3Dtrue%26pv%3D56px%26ph%3D56px%26ln%3Dfalse%26fl%3D1%26fm%3DHack%26fs%3D14px%26lh%3D143%2525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3Dconst%252520RouteWrapper%252520%25253D%252520%28%25257BComponent%25252C%252520...props%252520%25257D%29%252520%25253D%25253E%252520%25257B%25250A%252509const%252520auth%252520%25253D%252520checkAuth%28%29%25253B%25250A%25250A%252509let%252520role%252520%25253D%252520getUserRole%28%29%25252C%25250A%252509%252509access%252520%25253D%252520checkAccess%28userRole%25252C%252520props.roles%29%25253B%25250A%25250A%252509if%252520%28%21auth%29%252520%25257B%25250A%252509%252509logout%28%29%25253B%25250A%252509%25257D%252520else%252520if%252520%28auth%252520%252526%252526%252520%21access%29%252520%25257B%25250A%252509%252509return%252520%25253CRedirect%252520to%25253D%252522%25252Ferror%25252F401%252522%252520%25252F%25253E%25253B%25250A%252509%25257D%25250A%25250A%252509return%252520%28%25250A%252509%252509%25253CRoute%25250A%252509%252509%252509%25257B...props%25257D%25250A%252509%252509%252509render%25253D%25257BrouteProps%252520%25253D%25253E%252520%25253CComponent%252520%25257B...routeProps%25257D%252520%25252F%25253E%25257D%25250A%252509%252509%25252F%25253E%25250A%252509%29%25253B%25250A%25257D%25253B&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2F%3Fbg%3Drgba%2833%25252C7%25252C46%25252C1%29%26t%3Dsynthwave-84%26wt%3Dnone%26l%3Dauto%26ds%3Dfalse%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dfalse%26wa%3Dtrue%26pv%3D56px%26ph%3D56px%26ln%3Dfalse%26fl%3D1%26fm%3DHack%26fs%3D14px%26lh%3D143%252525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3Dconst%25252520RouteWrapper%25252520%2525253D%25252520%28%2525257BComponent%2525252C%25252520...props%25252520%2525257D%29%25252520%2525253D%2525253E%25252520%2525257B%2525250A%25252509const%25252520auth%25252520%2525253D%25252520checkAuth%28%29%2525253B%2525250A%2525250A%25252509let%25252520role%25252520%2525253D%25252520getUserRole%28%29%2525252C%2525250A%25252509%25252509access%25252520%2525253D%25252520checkAccess%28userRole%2525252C%25252520props.roles%29%2525253B%2525250A%2525250A%25252509if%25252520%28%21auth%29%25252520%2525257B%2525250A%25252509%25252509logout%28%29%2525253B%2525250A%25252509%2525257D%25252520else%25252520if%25252520%28auth%25252520%25252526%25252526%25252520%21access%29%25252520%2525257B%2525250A%25252509%25252509return%25252520%2525253CRedirect%25252520to%2525253D%25252522%2525252Ferror%2525252F401%25252522%25252520%2525252F%2525253E%2525253B%2525250A%25252509%2525257D%2525250A%2525250A%25252509return%25252520%28%2525250A%25252509%25252509%2525253CRoute%2525250A%25252509%25252509%25252509%2525257B...props%2525257D%2525250A%25252509%25252509%25252509render%2525253D%2525257BrouteProps%25252520%2525253D%2525253E%25252520%2525253CComponent%25252520%2525257B...routeProps%2525257D%25252520%2525252F%2525253E%2525257D%2525250A%25252509%25252509%2525252F%2525253E%2525250A%25252509%29%2525253B%2525250A%2525257D%2525253B&amp;image=https%3A%2F%2Fcarbon.now.sh%2Fstatic%2Fbrand%2Fbanner.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/0ecfb587b03ce2147db90cd55e1bf339/href">https://medium.com/media/0ecfb587b03ce2147db90cd55e1bf339/href</a></iframe><p>route wrapper here will check for authentication data and access based on the role needed by route and user role matrix. If you are un-authenticated the app will log you out to prevent conflicts, If you are authenticated but not authorised to access the route we will redirect to an error page. If your authenticated and authorised we will finally render the component. This check happens on all route changes for our protected routes.</p><h3>2. <strong>Restricting access to a part of the page </strong>🚏<strong>:</strong></h3><p>There might be certain situations where you might want to block features or a section of a page (route) while granting access to others. Here’s how we do it.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%3Fbg%3Drgba%2833%252C7%252C46%252C1%29%26t%3Dsynthwave-84%26wt%3Dnone%26l%3Djsx%26ds%3Dfalse%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dfalse%26wa%3Dtrue%26pv%3D56px%26ph%3D56px%26ln%3Dfalse%26fl%3D1%26fm%3DHack%26fs%3D14px%26lh%3D143%2525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3Dimport%252520%25257B%252520useSelector%252520%25257D%252520from%252520%2527react-redux%2527%25253B%25250Aimport%252520%25257B%252520allowedUserChecker%252520%25257D%252520from%252520%2527utils%2527%25253B%25250Aimport%252520PropTypes%252520from%252520%2527prop-types%2527%25253B%25250A%25250Aconst%252520RBAC%252520%25253D%252520%28%25257B%252520allowedRoles%25252C%252520children%252520%25257D%29%252520%25253D%25253E%252520%25257B%25250A%252509let%252520userRoles%252520%25253D%252520useSelector%28state%252520%25253D%25253E%252520state.userInfo.roles%29%25253B%25250A%252509let%252520access%252520%25253D%252520allowedUserChecker%28userRoles%25252C%252520allowedRoles%29%25253B%25250A%252509return%252520access%252520%252526%252526%252520children%25253B%25250A%25257D%25253B%25250A%25250ARBAC.propTypes%252520%25253D%252520%25257B%25250A%252509allowedRoles%25253A%252520PropTypes.arrayOf%28PropTypes.string%29%25252C%25250A%252509children%25253A%252520PropTypes.element%25250A%25257D%25253B%25250A%25250Aexport%252520default%252520RBAC%25253B&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2F%3Fbg%3Drgba%2833%25252C7%25252C46%25252C1%29%26t%3Dsynthwave-84%26wt%3Dnone%26l%3Djsx%26ds%3Dfalse%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dfalse%26wa%3Dtrue%26pv%3D56px%26ph%3D56px%26ln%3Dfalse%26fl%3D1%26fm%3DHack%26fs%3D14px%26lh%3D143%252525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3Dimport%25252520%2525257B%25252520useSelector%25252520%2525257D%25252520from%25252520%27react-redux%27%2525253B%2525250Aimport%25252520%2525257B%25252520allowedUserChecker%25252520%2525257D%25252520from%25252520%27utils%27%2525253B%2525250Aimport%25252520PropTypes%25252520from%25252520%27prop-types%27%2525253B%2525250A%2525250Aconst%25252520RBAC%25252520%2525253D%25252520%28%2525257B%25252520allowedRoles%2525252C%25252520children%25252520%2525257D%29%25252520%2525253D%2525253E%25252520%2525257B%2525250A%25252509let%25252520userRoles%25252520%2525253D%25252520useSelector%28state%25252520%2525253D%2525253E%25252520state.userInfo.roles%29%2525253B%2525250A%25252509let%25252520access%25252520%2525253D%25252520allowedUserChecker%28userRoles%2525252C%25252520allowedRoles%29%2525253B%2525250A%25252509return%25252520access%25252520%25252526%25252526%25252520children%2525253B%2525250A%2525257D%2525253B%2525250A%2525250ARBAC.propTypes%25252520%2525253D%25252520%2525257B%2525250A%25252509allowedRoles%2525253A%25252520PropTypes.arrayOf%28PropTypes.string%29%2525252C%2525250A%25252509children%2525253A%25252520PropTypes.element%2525250A%2525257D%2525253B%2525250A%2525250Aexport%25252520default%25252520RBAC%2525253B&amp;image=https%3A%2F%2Fcarbon.now.sh%2Fstatic%2Fbrand%2Fbanner.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/ff807c9b89d4fc348602f0b30605dfe5/href">https://medium.com/media/ff807c9b89d4fc348602f0b30605dfe5/href</a></iframe><p>This is a RBAC HOC ( <a href="https://reactjs.org/docs/higher-order-components.html">higher order components</a> ) we get the user roles from a global store (can be through other means as well) and we try to derive the access based on user role matrix check. We render the wrapped component only if access is permitted.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%3Fbg%3Drgba%2833%252C7%252C46%252C1%29%26t%3Dsynthwave-84%26wt%3Dnone%26l%3Djsx%26ds%3Dfalse%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dfalse%26wa%3Dtrue%26pv%3D56px%26ph%3D56px%26ln%3Dfalse%26fl%3D1%26fm%3DHack%26fs%3D14px%26lh%3D143%2525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3Dimport%252520RBAC%252520from%252520%2527.%25252Fdir%25252FRBAC%2527%25253B%25250A...%25250A%25253CRBAC%252520allowedRoles%25253D%25257B%25255B%252520%2527ROLE_AUTHOR%2527%25252C%252520%2527ROLE_ADMIN%2527%25255D%25257D%25253E%25250A%252520%252520%252520%252520%25253CButton%252520type%25253D%252522submit%252522%252520label%25253D%252522VERIFY%252520AND%252520PUBLISH%252522%252520%25252F%25253E%25250A%25253C%25252FRBAC%25253E%25250A...&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2F%3Fbg%3Drgba%2833%25252C7%25252C46%25252C1%29%26t%3Dsynthwave-84%26wt%3Dnone%26l%3Djsx%26ds%3Dfalse%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dfalse%26wa%3Dtrue%26pv%3D56px%26ph%3D56px%26ln%3Dfalse%26fl%3D1%26fm%3DHack%26fs%3D14px%26lh%3D143%252525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3Dimport%25252520RBAC%25252520from%25252520%27.%2525252Fdir%2525252FRBAC%27%2525253B%2525250A...%2525250A%2525253CRBAC%25252520allowedRoles%2525253D%2525257B%2525255B%25252520%27ROLE_AUTHOR%27%2525252C%25252520%27ROLE_ADMIN%27%2525255D%2525257D%2525253E%2525250A%25252520%25252520%25252520%25252520%2525253CButton%25252520type%2525253D%25252522submit%25252522%25252520label%2525253D%25252522VERIFY%25252520AND%25252520PUBLISH%25252522%25252520%2525252F%2525253E%2525250A%2525253C%2525252FRBAC%2525253E%2525250A...&amp;image=https%3A%2F%2Fcarbon.now.sh%2Fstatic%2Fbrand%2Fbanner.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/a713a431c4f9c3197ce452b048f2d628/href">https://medium.com/media/a713a431c4f9c3197ce452b048f2d628/href</a></iframe><h3>3. <strong>Securing Backend Endpoints </strong>🔗:</h3><p>Last but not the least we need to make sure the backend secures their API’s from their end as well.</p><blockquote>Well there are a ton of ways to do this using some API gateway, Proxy Servers etc., For the sake of simplicity I’m assuming certain parameters. These parameters are not necessary and you can implement the logic in way that you need as the crux is core logic only.</blockquote><p>First thing first you’ll need a role to routes file similar to what we saw in frontend.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%3Fbg%3Drgba%28248%252C231%252C28%252C1%29%26t%3Dsynthwave-84%26wt%3Dnone%26l%3Dauto%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D56px%26ph%3D56px%26ln%3Dfalse%26fl%3D1%26fm%3DHack%26fs%3D14px%26lh%3D133%2525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3Dmodule.exports%252520%25253D%252520%25257B%25250A%252509homePage%25253A%252520%25257B%25250A%252509%252509route%25253A%252520%2527%25252F%2527%25252C%25250A%252509%252509roles%25253A%252520%25255B%2527ROLE_TEACHER%2527%25252C%252520%2527ROLE_ADMIN%2527%25252C%252520%2527ROLE_EXTERNAL_SOURCER%2527%25255D%25250A%252509%25257D%25252C%25250A%252509createQuestion%25253A%252520%25257B%25250A%252509%252509route%25253A%252520%2527%25252Fquestion-bank%25252Fcreate%25252F%25253Atype%25252F%2527%25252C%25250A%252509%252509roles%25253A%252520%25255B%2527ROLE_TEACHER%2527%25252C%252520%2527ROLE_ADMIN%2527%25252C%252520%2527ROLE_EXTERNAL_SOURCER%2527%25255D%25250A%252509%25257D%25252C%25250A%252509testAttempt%25253A%252520%25257B%25250A%252509%252509route%25253A%252520%2527%25252Fstudent%25252Ftest%25252F%25253Agid%2527%25252C%25250A%252509%252509roles%25253A%252520%25255B%2527ROLE_TEACHER%2527%25252C%252520%2527ROLE_ADMIN%2527%25252C%252520%2527ROLE_STUDENT%2527%25255D%25250A%252509%25257D%25250A%25257D%25253B&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2F%3Fbg%3Drgba%28248%25252C231%25252C28%25252C1%29%26t%3Dsynthwave-84%26wt%3Dnone%26l%3Dauto%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D56px%26ph%3D56px%26ln%3Dfalse%26fl%3D1%26fm%3DHack%26fs%3D14px%26lh%3D133%252525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3Dmodule.exports%25252520%2525253D%25252520%2525257B%2525250A%25252509homePage%2525253A%25252520%2525257B%2525250A%25252509%25252509route%2525253A%25252520%27%2525252F%27%2525252C%2525250A%25252509%25252509roles%2525253A%25252520%2525255B%27ROLE_TEACHER%27%2525252C%25252520%27ROLE_ADMIN%27%2525252C%25252520%27ROLE_EXTERNAL_SOURCER%27%2525255D%2525250A%25252509%2525257D%2525252C%2525250A%25252509createQuestion%2525253A%25252520%2525257B%2525250A%25252509%25252509route%2525253A%25252520%27%2525252Fquestion-bank%2525252Fcreate%2525252F%2525253Atype%2525252F%27%2525252C%2525250A%25252509%25252509roles%2525253A%25252520%2525255B%27ROLE_TEACHER%27%2525252C%25252520%27ROLE_ADMIN%27%2525252C%25252520%27ROLE_EXTERNAL_SOURCER%27%2525255D%2525250A%25252509%2525257D%2525252C%2525250A%25252509testAttempt%2525253A%25252520%2525257B%2525250A%25252509%25252509route%2525253A%25252520%27%2525252Fstudent%2525252Ftest%2525252F%2525253Agid%27%2525252C%2525250A%25252509%25252509roles%2525253A%25252520%2525255B%27ROLE_TEACHER%27%2525252C%25252520%27ROLE_ADMIN%27%2525252C%25252520%27ROLE_STUDENT%27%2525255D%2525250A%25252509%2525257D%2525250A%2525257D%2525253B&amp;image=https%3A%2F%2Fcarbon.now.sh%2Fstatic%2Fbrand%2Fbanner.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/087d1d9433292ee3d4be959bb76eb4dd/href">https://medium.com/media/087d1d9433292ee3d4be959bb76eb4dd/href</a></iframe><p>ℹ️ <em>This might be a duplicate but try to host this somewhere common to solve your DRY OCD </em>💠<em> issues if any </em>😂<em> .</em></p><p>then this RBAC middleware below will help manage things for you automatically. Here it’s pretty simple check access and authorise / respond with error.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%3Fbg%3Drgba%289%252C17%252C61%252C1%29%26t%3Dcobalt%26wt%3Dnone%26l%3Dauto%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D56px%26ph%3D56px%26ln%3Dfalse%26fl%3D1%26fm%3DIBM%2520Plex%2520Mono%26fs%3D14px%26lh%3D143%2525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3Dmodule.exports%252520%25253D%252520%28rolesWithAccess%29%252520%25253D%25253E%252520%25257B%25250A%252520%252520let%252520%25257Broles%25257D%252520%25253D%252520req.user%25253B%25250A%252520%252520%25252F%25252F%252520eg%25253A%252520%252520roles%252520%25253D%252520%25255B%2527author%2527%25255D%252520comming%252520from%252520JWT%252520token%25250A%252520%252520return%252520%28req%25252C%252520res%25252C%252520next%29%252520%25253D%25253E%252520%25257B%25250A%252520%252520%252520%252520if%252520%28rolesWithAccess.length%252520%252526%252526%252520%21rolesWithAccess.includes%28roles%29%29%252520%25257B%25250A%252520%252520%252520%252520%252520%252520return%252520res.status%28401%29.json%28%25257B%252520message%25253A%252520%2527Unauthorized%2527%252520%25257D%29%25253B%25250A%252520%252520%252520%252520%252520%252520%25252F%25252F%252520send%252520however%252520you%252520want%252520this%252520one%252520way%252520of%252520sending%252520it.%25250A%252520%252520%252520%252520%25257D%252520else%252520%25257B%25250A%252520%252520%252520%252520%252520%252520next%28%29%25253B%25250A%252520%252520%252520%252520%25257D%25250A%252520%252520%25257D%25250A%25257D%25253B&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2F%3Fbg%3Drgba%289%25252C17%25252C61%25252C1%29%26t%3Dcobalt%26wt%3Dnone%26l%3Dauto%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D56px%26ph%3D56px%26ln%3Dfalse%26fl%3D1%26fm%3DIBM%252520Plex%252520Mono%26fs%3D14px%26lh%3D143%252525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3Dmodule.exports%25252520%2525253D%25252520%28rolesWithAccess%29%25252520%2525253D%2525253E%25252520%2525257B%2525250A%25252520%25252520let%25252520%2525257Broles%2525257D%25252520%2525253D%25252520req.user%2525253B%2525250A%25252520%25252520%2525252F%2525252F%25252520eg%2525253A%25252520%25252520roles%25252520%2525253D%25252520%2525255B%27author%27%2525255D%25252520comming%25252520from%25252520JWT%25252520token%2525250A%25252520%25252520return%25252520%28req%2525252C%25252520res%2525252C%25252520next%29%25252520%2525253D%2525253E%25252520%2525257B%2525250A%25252520%25252520%25252520%25252520if%25252520%28rolesWithAccess.length%25252520%25252526%25252526%25252520%21rolesWithAccess.includes%28roles%29%29%25252520%2525257B%2525250A%25252520%25252520%25252520%25252520%25252520%25252520return%25252520res.status%28401%29.json%28%2525257B%25252520message%2525253A%25252520%27Unauthorized%27%25252520%2525257D%29%2525253B%2525250A%25252520%25252520%25252520%25252520%25252520%25252520%2525252F%2525252F%25252520send%25252520however%25252520you%25252520want%25252520this%25252520one%25252520way%25252520of%25252520sending%25252520it.%2525250A%25252520%25252520%25252520%25252520%2525257D%25252520else%25252520%2525257B%2525250A%25252520%25252520%25252520%25252520%25252520%25252520next%28%29%2525253B%2525250A%25252520%25252520%25252520%25252520%2525257D%2525250A%25252520%25252520%2525257D%2525250A%2525257D%2525253B&amp;image=https%3A%2F%2Fcarbon.now.sh%2Fstatic%2Fbrand%2Fbanner.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/8b3c1ed0547a1d6f971c8c1ec13ec643/href">https://medium.com/media/8b3c1ed0547a1d6f971c8c1ec13ec643/href</a></iframe><p>Now we need to wire it up with our route like this. Thats it we got them unauthorised users 🛑</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%3Fbg%3Drgba%289%252C17%252C61%252C1%29%26t%3Dcobalt%26wt%3Dnone%26l%3Djavascript%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D56px%26ph%3D56px%26ln%3Dfalse%26fl%3D1%26fm%3DIBM%2520Plex%2520Mono%26fs%3D14px%26lh%3D143%2525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3Dconst%252520routes%252520from%252520%2527.%25252Fdir%25252Froutes%2527%25253B%25250Aconst%252520rbac%252520from%252520%2527%25252Fdir%25252Fto%25252Frbac%2527%25253B%25250Aconst%252520publishController%252520from%252520%2527%25252Fdir%25252Fto%25252Fcontrollers%2527%25253B%25250A%25250A...%25250A%25250Aapp.use%28routes.publish.route%25252C%252520rbac%28routes.publish.roles%29%25252C%252520publishController%29%25253B%25250A%25250A...&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2F%3Fbg%3Drgba%289%25252C17%25252C61%25252C1%29%26t%3Dcobalt%26wt%3Dnone%26l%3Djavascript%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D56px%26ph%3D56px%26ln%3Dfalse%26fl%3D1%26fm%3DIBM%252520Plex%252520Mono%26fs%3D14px%26lh%3D143%252525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3Dconst%25252520routes%25252520from%25252520%27.%2525252Fdir%2525252Froutes%27%2525253B%2525250Aconst%25252520rbac%25252520from%25252520%27%2525252Fdir%2525252Fto%2525252Frbac%27%2525253B%2525250Aconst%25252520publishController%25252520from%25252520%27%2525252Fdir%2525252Fto%2525252Fcontrollers%27%2525253B%2525250A%2525250A...%2525250A%2525250Aapp.use%28routes.publish.route%2525252C%25252520rbac%28routes.publish.roles%29%2525252C%25252520publishController%29%2525253B%2525250A%2525250A...&amp;image=https%3A%2F%2Fcarbon.now.sh%2Fstatic%2Fbrand%2Fbanner.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/08ad589905f9c914b2661d09eb256ce2/href">https://medium.com/media/08ad589905f9c914b2661d09eb256ce2/href</a></iframe><h3>Stay tuned 🕐 for part 2 of this article I might write about implementation other platform such as Next JS and GraphQL.</h3><p>I’m sure there are modifications / implementations to better the above article and also fun fact route paths can be a regex(<strong>/^\/(api|rest)\/.+$/</strong>) this is something that now many of you may know. Likewise, my work at <a href="https://www.upgrad.com/about/"><strong>upGrad</strong></a><strong> </strong>is now only about learning new things to better my career but also to build a platform that empowers multiple people in transitioning their careers as well. Do visit <a href="https://www.upgrad.com/"><strong>upGrad.com</strong></a> to check out our programs that are completely online! If you wish to work with our ever-enthusiastic team, check out <a href="https://www.upgrad.com/open-positions"><strong>our careers page</strong></a><strong>.</strong> We are always on the lookout for the ambitious, talented folks!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9294146dc6e3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/technology-at-upgrad/how-to-role-based-access-control-9294146dc6e3">How to Role Based Access Control (RBAC) ? 👮‍♂️⚠️</a> was originally published in <a href="https://medium.com/technology-at-upgrad">Technology at upGrad</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>