<?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 Hamza Naveed on Medium]]></title>
        <description><![CDATA[Stories by Hamza Naveed on Medium]]></description>
        <link>https://medium.com/@hamzanaveedmalik?source=rss-174598a831cf------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*z3FHR1RTo1Y7qcWGE7ct0Q.jpeg</url>
            <title>Stories by Hamza Naveed on Medium</title>
            <link>https://medium.com/@hamzanaveedmalik?source=rss-174598a831cf------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 05:38:05 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@hamzanaveedmalik/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[Handling session timeout in a React application]]></title>
            <link>https://medium.com/@hamzanaveedmalik/handling-session-timeout-in-a-react-application-ec7e29c3732c?source=rss-174598a831cf------2</link>
            <guid isPermaLink="false">https://medium.com/p/ec7e29c3732c</guid>
            <dc:creator><![CDATA[Hamza Naveed]]></dc:creator>
            <pubDate>Tue, 24 Jan 2023 20:36:07 GMT</pubDate>
            <atom:updated>2023-01-24T21:22:36.631Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CPwi6ZpWXdbi2-ZpKEqNtw.jpeg" /><figcaption>Session timeout in React is a simple yet tricky business. As if navigating through sand dunes.</figcaption></figure><blockquote>Session timeout is an important security feature that helps protect against unauthorised access to a user’s account. In a React application, there are several ways to implement session timeout.</blockquote><p>There are several ways to handle session timeout and in this article, we will discuss the most common methods, their pros and cons, and the best practices to implement them.</p><ol><li><strong>Using the JavaScript </strong><strong>setTimeout() function</strong></li></ol><p>The setTimeout() function is a JavaScript function that can be used to set a timer that triggers a logout event after a certain period of inactivity.<br>This method is simple to implement, and it can be easily customised to fit the specific requirements of the application.</p><p><strong>Pros:</strong></p><ul><li>Easy to implement</li><li>Can be easily customised to fit the specific requirements of the application</li></ul><p><strong>Cons:</strong></p><ul><li>Does not account for user activity, so if the user is active on the page the session will not timeout</li><li>Does not work when the user is inactive in other tabs or windows</li></ul><p><strong>2. Using the HTML meta refresh tag</strong></p><p>The meta refresh tag is an HTML tag that can be used to refresh the page after a certain period of inactivity and redirect the user to the login page.<br>This method is also simple to implement, and it can be easily customised to fit the specific requirements of the application.</p><p><strong>Pros:</strong></p><ul><li>Easy to implement</li><li>Can be easily customised to fit the specific requirements of the application</li></ul><p><strong>Cons</strong>:</p><ul><li>Does not account for user activity</li><li>Can be disruptive for the user if they are actively using the application</li><li>Not fully supported by all the browsers</li></ul><p><strong>3. Using the </strong><strong>react-idle-timer library</strong></p><p>The react-idle-timer library is a higher-order component that can be used to detect user activity and trigger a logout event.<br>This method provides a more sophisticated approach to session timeout, and it is more user-friendly than the previous two methods.</p><p><strong>Pros:</strong></p><ul><li>Detects user activity</li><li>More user-friendly</li><li>Wraps around the setTimeout function</li></ul><p><strong>Cons:</strong></p><ul><li>Additional library dependency</li><li>More complex to implement than the previous two methods</li></ul><p><strong>4. Using the </strong><strong>react-timeout library</strong></p><p>The react-timeout library is a way to handle timeouts in a React application using a declarative approach.</p><p>This method is similar to the setTimeout() method, but it offers a more elegant and declarative way to handle timeouts in a React application.</p><p><strong>Pros:</strong></p><ul><li>Declarative approach</li><li>More elegant</li></ul><p><strong>Cons</strong>:</p><ul><li>Additional library dependency</li><li>Does not account for user activity</li></ul><p><strong>5. Using the </strong><strong>react-idle library</strong></p><p>The react-idle library is another way to detect user activity and trigger a logout event. It provides a way to detect user activity and trigger a logout event, similar to the react-idle-timer library.</p><p><strong>Pros:</strong></p><ul><li>Detects user activity</li><li>More user-friendly</li></ul><p><strong>Cons:</strong></p><ul><li>Additional library dependency</li><li>More complex to implement than the previous two methods</li></ul><p><strong>6. Using the </strong><strong>react-session-timeout library</strong></p><p>The react-session-timeout library is a more robust and easy to use library to handle session timeout. It allows you to customise the session timeout message and also handle logout events, similar to the react-idle-timer library.</p><p><strong>Pros:</strong></p><ul><li>Detects user activity</li><li>More user-friendly</li><li>Customisable session timeout message</li><li>Easy to implement</li></ul><p><strong>Cons:</strong></p><ul><li>Additional library dependency</li><li>Limited customisability compared to other methods</li></ul><p>In conclusion, there are several ways to handle session timeout in a React application. Each method has its own pros and cons, and it is important to consider the specific requirements of the application before choosing a method. Some methods are simple to implement but do not account for user activity, while others are more sophisticated but require additional library dependencies. The best practice is to use the most appropriate method that fits the specific requirements of the application, and to consider the user experience.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ec7e29c3732c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[gRPC vs. REST: What is the difference?]]></title>
            <link>https://medium.com/@hamzanaveedmalik/grpc-vs-rest-what-is-the-difference-f48ac44374c7?source=rss-174598a831cf------2</link>
            <guid isPermaLink="false">https://medium.com/p/f48ac44374c7</guid>
            <category><![CDATA[grpc]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[rest]]></category>
            <category><![CDATA[api-development]]></category>
            <dc:creator><![CDATA[Hamza Naveed]]></dc:creator>
            <pubDate>Tue, 03 Jan 2023 15:55:17 GMT</pubDate>
            <atom:updated>2023-01-04T01:02:59.358Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>gRPC vs. REST: How Does gRPC Compare with Traditional REST APIs.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Nt_h0LDmqXJn1dxXYEFdxw.jpeg" /></figure><h3>gRPC</h3><p>gRPC is a modern, open-source, high-performance remote procedure call (RPC) framework that can run in any environment. It uses HTTP/2 for transport, Protocol Buffers for encoding, and provides features such as authentication, bidirectional streaming, and flow control, making it a powerful tool for building scalable, reliable APIs.</p><h3>REST</h3><p>On the other hand, REST (Representational State Transfer) is a design style for building APIs that use HTTP for communication. REST APIs are based on the HTTP protocol and use standard HTTP verbs (such as GET, POST, PUT, DELETE, etc.) to perform operations on resources.</p><p><em>Here are some key differences between gRPC and REST:</em></p><ol><li><strong>Data encoding</strong>: gRPC uses Protocol Buffers (also known as protobufs) for data serialization, while REST APIs use formats such as JSON or XML. Protobufs are generally more efficient and faster to serialize and deserialize compared to JSON or XML.</li><li><strong>API design</strong>: gRPC uses a service-oriented design, where a service is defined by a collection of methods that can be called remotely, while REST APIs use a resource-oriented design, where the API is centered around resources and HTTP verbs are used to perform operations on these resources.</li><li><strong>Communication style</strong>: gRPC supports both unary (single request/response) and streaming communication styles, while REST only supports the unary style. This means that gRPC can be used to build APIs that support streaming data, such as real-time updates or live media streaming.</li><li><strong>Performance</strong>: gRPC generally has better performance compared to REST due to its use of HTTP/2 and protobufs. HTTP/2 allows for multiplexing requests over a single connection and provides features such as flow control and header compression, while protobufs are faster and more efficient than JSON or XML.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f48ac44374c7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a React-Redux-NodeJS-Mongo application using Material-UI]]></title>
            <link>https://medium.com/@hamzanaveedmalik/building-a-react-redux-nodejs-mongo-application-using-material-ui-33071186914d?source=rss-174598a831cf------2</link>
            <guid isPermaLink="false">https://medium.com/p/33071186914d</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[mongoose]]></category>
            <category><![CDATA[material-ui]]></category>
            <category><![CDATA[mongodb]]></category>
            <category><![CDATA[redux]]></category>
            <dc:creator><![CDATA[Hamza Naveed]]></dc:creator>
            <pubDate>Wed, 11 Mar 2020 10:45:57 GMT</pubDate>
            <atom:updated>2020-03-11T10:45:57.051Z</atom:updated>
            <content:encoded><![CDATA[<p><em>The article describes how I worked through a technical assessment. Keeping in mind the criteria for the assessment, I’ve concealed all the relevant information about the assessment provider.</em></p><p>Recently, I was working on an exciting application scenario; where I was provided with a mission to create a web app where users can <strong>check-in</strong> with how they are feeling. The requirements of the project were to have an understanding of Javascript across the stack and knowledge of REST APIs and a modern Javascript framework.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hqeUL3pHvQuDZpLs3X3xmQ.png" /><figcaption>Cover photo is designed using Sketch app.</figcaption></figure><h3>The Backend</h3><p>I started with the bottom-up approach; with working on back-end first. Setting up a MongoDB using <a href="https://mlab.com/"><strong>mLab</strong></a> cloud database service featuring automated provisioning and scaling of MongoDB databases.</p><p>Next, I set up a server using ExpressJS. Express comes with a myriad of HTTP utility methods and middleware at your disposal, creating a quick, easy and robust API. For establishing a connection between NodeJS and MongoDB, I used <a href="https://mongoosejs.com/"><strong>MongooseJS</strong></a>, which is ODM (Object Data Modelling) Library and provides a straight-forward, schema-based solution to model your application data. Since it is a basic application with basic functionality; only two routes were defined for reading from writing to the db; <strong><em>get </em></strong>and <strong><em>post</em></strong>.</p><p>ExpressJS comes with built-in security features, which I utilised to make my server application more secure. Some of the important security features considered were;</p><ul><li>Preventing DOS Attacks.</li><li>Preventing XXS Attacks.</li><li>Preventing Brute Force Attacks</li><li>Preventing SQL/NoSQL Injection Attacks</li></ul><p><em>Tada! </em>By the end of it, I was able to see a nice dataset of <em>mood checkins</em>, coming through my locally set up API.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fWumMPKrcd-N8byZek9suA.png" /></figure><h3>The Frontend</h3><p>Next up, I used <em>create-react-app </em>boilerplate to setup the client-side application in React and was ready to get going from there. While working on the client-side, I planned to build two pages, which would comprise of several components. The two pages being, a form for mood check-in and a page to display history of check-ins. I leveraged using Material-UI Library for building React components. It provides tons of terrific features including dynamic styles generated at runtime, nested themes with intuitive overrides and most importantly reduced load time with code splitting. Besides, it looks clean.</p><p>After my application started to look into some shape, I moved on to integrate Redux into my client side application. The reason for implementing Redux was to keep the state of my application in a store, and each component can access any state that it needs from this store.</p><p>After completing the Redux implementation, this is how the application began to look.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zFaWWn3v1n7eLPvShyWw4g.png" /><figcaption>Mood Check-In Page</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3Y_53TnG8UfrWN1UY2alDA.png" /><figcaption>Mood Insights Page</figcaption></figure><h3>Improvements</h3><p>There are several areas in this application which can be improved. In my opinion the biggest room for improvement lies with <strong>testing</strong>. For the server-side, a test suite could be introduced to validate mongoose models and the functions. Similarly automated tests, (unit tests) for client-side could greatly improve the overall quality and refactor ability of the code. Along with that, some <strong><em>toasts</em></strong> could be included for showing success or error messages.</p><h3>Conclusion</h3><p>One really important learning outcome from this assessment was to keep practising the basics as an Engineer. It also provided an opportunity to play around with some of the technologies I don’t get to work with on day-to-day basis like Material-UI, MongooseJS and mLab. Working with one thing, leads to learning another. Now, I’m planning of using AWS provided by mLabs to create lambda function for this application. The purpose is to keep on improving.</p><p>Thank you for reading this article, I’ve thoroughly enjoyed working on this assessment.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=33071186914d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What is Hoisting in Javascript?]]></title>
            <link>https://medium.com/@hamzanaveedmalik/what-is-hoisting-in-javascript-33499b1b0ca9?source=rss-174598a831cf------2</link>
            <guid isPermaLink="false">https://medium.com/p/33499b1b0ca9</guid>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Hamza Naveed]]></dc:creator>
            <pubDate>Fri, 28 Sep 2018 11:08:38 GMT</pubDate>
            <atom:updated>2018-09-28T11:08:38.299Z</atom:updated>
            <content:encoded><![CDATA[<p>Hoisting is a JavaScript mechanism where variables and function declarations are moved to the top of their scope before code execution.</p><p>Inevitably, this means that no matter where functions and variables are declared, they are moved to the top of their scope regardless of whether their scope is global or local.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=33499b1b0ca9" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>