{"componentChunkName":"component---src-templates-blog-list-template-js","path":"/engineering/33","result":{"data":{"allMarkdownRemark":{"edges":[{"node":{"excerpt":"Snapshot Testing Snapshot tests as the name implies, is a very powerful tool to test whether you the UI has change or not. A typical…","fields":{"slug":"/engineering/snapshot-testing-using-nightwatch-and-mocha/"},"html":"<h3 id=\"snapshot-testing\" style=\"position:relative;\"><a href=\"#snapshot-testing\" aria-label=\"snapshot testing permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Snapshot Testing</h3>\n<p><strong>Snapshot tests</strong> as the name implies, is a very powerful tool to test whether you the UI has change or not. A typical <strong>snapshot test</strong> case for a website/mobile app renders a UI component, takes a <strong>snapshot</strong>, then compares it to a reference <strong>snapshot</strong> file stored alongside the <strong>test</strong>.</p>\n<h3 id=\"snapshot-testing--benefits\" style=\"position:relative;\"><a href=\"#snapshot-testing--benefits\" aria-label=\"snapshot testing  benefits permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Snapshot Testing  Benefits</h3>\n<h4 id=\"for-qa-manual-and-automation\" style=\"position:relative;\"><a href=\"#for-qa-manual-and-automation\" aria-label=\"for qa manual and automation permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>For QA Manual And Automation</h4>\n<ul>\n<li>Easy to identify any change in the DOM element.</li>\n<li>Help to automation to check element id as same as previous.</li>\n<li>Help to check integration testing will be in right.</li>\n</ul>\n<h4 id=\"for-developer-unit-testing\" style=\"position:relative;\"><a href=\"#for-developer-unit-testing\" aria-label=\"for developer unit testing permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>For Developer Unit Testing</h4>\n<ul>\n<li>The developer can compare snapshot dom on every movement when the dynamic change happened on DOM.</li>\n<li>Get changes in DOM and update QA for update automation testing products.</li>\n</ul>\n<p>Need to install <strong>NPM</strong></p>\n<ol>\n<li>npm i mocha</li>\n<li>npm i clean-html</li>\n<li>npm i snap-shot</li>\n<li>npm i jsdom</li>\n<li>npm i jsdom-global</li>\n</ol>\n<blockquote>\n<p> <strong>NightWatch</strong> does not have snapshot feature. So, We will use <strong>mocha</strong> to take snapshots. But <strong>Mocha will be run by NightWatch.</strong></p>\n</blockquote>\n<h3 id=\"directory-structure\" style=\"position:relative;\"><a href=\"#directory-structure\" aria-label=\"directory structure permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Directory Structure</h3>\n<p>As per over automation project. We have created a \"snapshot\" folder under the \"test\" folder and we will be following the same structure as per the below project menu bar. </p>\n<p><a href=\"https://cdn.filestackcontent.com/solmjUZXTPWZgTNppBmW\"><img src=\"https://cdn.filestackcontent.com/solmjUZXTPWZgTNppBmW\" alt=\"N|Solid\"></a></p>\n<p>We also need to add Mocha test files, which will use to take snapshot and store under the root folder \"__snapshots__\".</p>\n<p><img src=\"https://cdn.filestackcontent.com/XGkI0wDrQoGDSp2djINg\" alt=\"(https://cdn.filestackcontent.com/XGkI0wDrQoGDSp2djINg)\"></p>\n<p>If you are running automation code via visual code editor, then you can setup a launch.json file which helps you to debug your test code with all file/individual file.</p>\n<p>You can see the settings below of the launch.json file.</p>\n<p><img src=\"https://cdn.filestackcontent.com/qDjAHwHIQtKp2hmBdaEn\" alt=\"(https://cdn.filestackcontent.com/qDjAHwHIQtKp2hmBdaEn)\"></p>\n<hr>\n<h4 id=\"update-snapshot\" style=\"position:relative;\"><a href=\"#update-snapshot\" aria-label=\"update snapshot permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Update Snapshot</h4>\n<p>After creating a snapshot, sometimes we need to update snapshot due to improvement, customer requirements, and any valid changes on UI. So here, we can have some other settings which  will help us.</p>\n<ol>\n<li>\n<p>If we want to update all snapshots by single command then we need to follow below instruction.</p>\n<p>Create a root folder file(update_snapshot.js) and paste code on it.</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"javascript\" data-index=\"0\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk1\">(</span><span class=\"mtk4\">function</span><span class=\"mtk1\">(){</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">      </span><span class=\"mtk12\">process</span><span class=\"mtk1\">.</span><span class=\"mtk12\">env</span><span class=\"mtk1\">.</span><span class=\"mtk12\">UPDATE</span><span class=\"mtk1\">\\=</span><span class=\"mtk7\">1</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">})()</span></span></code></pre>\n<p>Add in package.json</p>\n<p>  <img src=\"https://cdn.filestackcontent.com/TTvchMDTW6F5x87J0688\" alt=\"(https://cdn.filestackcontent.com/TTvchMDTW6F5x87J0688)\"> </p>\n</li>\n</ol>\n<blockquote>\n<p>We can update all snapshot by using → <code>npm run snapshot-u</code></p>\n</blockquote>\n<ol start=\"2\">\n<li>If we want to update the single snapshot then we can use the above technique but we just need to update the file name against \"test/snapshot\".</li>\n<li>\n<p>If we use vscode, then we need to update launch.json as per above information </p>\n<p>  <img src=\"https://cdn.filestackcontent.com/uWX0pIUaSzKFyVKJGIYB\" alt=\"(https://cdn.filestackcontent.com/uWX0pIUaSzKFyVKJGIYB)\"></p>\n<p>  and need to create a file(\"snapshot.config.js\") in the root folder and paste the below code.</p>\n<p>  <img src=\"https://cdn.filestackcontent.com/Hh3PNxKmSo2pSFRA9YeM\" alt=\"(https://cdn.filestackcontent.com/Hh3PNxKmSo2pSFRA9YeM)\"></p>\n</li>\n</ol>\n<blockquote>\n<p>Important-: If we want to run only a snapshot test then we will need a small change in the nightwatch.json file.</p>\n</blockquote>\n<p><img src=\"https://cdn.filestackcontent.com/EkBrPZffRv2ElZ0Qez36\" alt=\"(https://cdn.filestackcontent.com/EkBrPZffRv2ElZ0Qez36)\"></p>\n<p>You can find the complete reposrtory link <a href=\"https://github.com/niteshjain1987/NightWatch-Snapshot\">here</a></p>\n<style class=\"grvsc-styles\">\n  .grvsc-container {\n    overflow: auto;\n    -webkit-overflow-scrolling: touch;\n    padding-top: 1rem;\n    padding-top: var(--grvsc-padding-top, var(--grvsc-padding-v, 1rem));\n    padding-bottom: 1rem;\n    padding-bottom: var(--grvsc-padding-bottom, var(--grvsc-padding-v, 1rem));\n    border-radius: 8px;\n    border-radius: var(--grvsc-border-radius, 8px);\n    font-feature-settings: normal;\n  }\n  \n  .grvsc-code {\n    display: inline-block;\n    min-width: 100%;\n  }\n  \n  .grvsc-line {\n    display: inline-block;\n    box-sizing: border-box;\n    width: 100%;\n    padding-left: 1.5rem;\n    padding-left: var(--grvsc-padding-left, var(--grvsc-padding-h, 1.5rem));\n    padding-right: 1.5rem;\n    padding-right: var(--grvsc-padding-right, var(--grvsc-padding-h, 1.5rem));\n  }\n  \n  .grvsc-line-highlighted {\n    background-color: var(--grvsc-line-highlighted-background-color, transparent);\n    box-shadow: inset var(--grvsc-line-highlighted-border-width, 4px) 0 0 0 var(--grvsc-line-highlighted-border-color, transparent);\n  }\n  \n  .dark-default-dark {\n    background-color: #1E1E1E;\n    color: #D4D4D4;\n  }\n  .dark-default-dark .mtk1 { color: #D4D4D4; }\n  .dark-default-dark .mtk4 { color: #569CD6; }\n  .dark-default-dark .mtk12 { color: #9CDCFE; }\n  .dark-default-dark .mtk7 { color: #B5CEA8; }\n</style>","frontmatter":{"date":"July 29, 2020","updated_date":null,"description":"Snapshot testing is one of many different testing tools, which compares the previous and current snapshot. Unlike TDD, snapshot testing relies on the fact that your component renders correctly already. ","title":"Snapshot testing using Nightwatch and mocha","tags":["QA","Nightwatch","snapshot-testing"],"pinned":null,"coverImage":{"childImageSharp":{"fluid":{"aspectRatio":1.7699115044247788,"src":"/static/858d55e4f691f5e5780be7675877f12d/58556/snapshot_nightwatch.webp","srcSet":"/static/858d55e4f691f5e5780be7675877f12d/61e93/snapshot_nightwatch.webp 200w,\n/static/858d55e4f691f5e5780be7675877f12d/1f5c5/snapshot_nightwatch.webp 400w,\n/static/858d55e4f691f5e5780be7675877f12d/58556/snapshot_nightwatch.webp 800w,\n/static/858d55e4f691f5e5780be7675877f12d/99238/snapshot_nightwatch.webp 1200w,\n/static/858d55e4f691f5e5780be7675877f12d/135cd/snapshot_nightwatch.webp 1280w","sizes":"(max-width: 800px) 100vw, 800px"}}},"author":{"id":"Nitesh Jain","github":"niteshjain1987","avatar":null}}}},{"node":{"excerpt":"Agile is becoming another SDLC methodology but in reality, it is beyond normal project management. With time It’s been accessorized a lot…","fields":{"slug":"/engineering/agile-development-team/"},"html":"<p>Agile is becoming another SDLC methodology but in reality, it is beyond normal project management. With time It’s been accessorized a lot and leaving behind the basic building blocks and the important entity the <strong>Agile Development Teams</strong>. </p>\n<p>Does anybody want a product full of bugs, non-scaleable, difficult to maintain?, certainly No.\nNo matter whatever the agile framework we use, the ultimate goal is a wonderful product with complete customer satisfaction. And it's the developers who sit in the centre and build the product and are responsible for the quality.</p>\n<p><strong><p style=\"text-align: center;\">Agile + Development Team = Agile Development Team</p></strong></p>\n<h2 id=\"what-is-agile-development-team\" style=\"position:relative;\"><a href=\"#what-is-agile-development-team\" aria-label=\"what is agile development team permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>What is Agile Development Team</h2>\n<p>Before that let’s see who are the developers and what is a development team. A developer is a proficient individual in his technical skills. And a group of such individuals working on a project/product makes a development team. Then how does an Agile Development Team differ? </p>\n<p>The three attributes bring that difference.</p>\n<p><em>“A group of proficient individuals who are cross-functional, autonomous and self-organised sharing the same goal of building a bug-free product or delivering the project with proven quality”</em></p>\n<h2 id=\"cross-functional\" style=\"position:relative;\"><a href=\"#cross-functional\" aria-label=\"cross functional permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Cross-functional</h2>\n<p>This doesn’t mean that every team member is <em>'master of all'</em> or even a <em>'jack of all trades'</em>. In fact, every individual carries their proficiency. But the important thing is that each team member is capable of building additional skills and as and when required can be applied during the development journey.</p>\n<p>It reduces the dependency and overall predictability increases and gives better room for risk management. </p>\n<h2 id=\"self-organised\" style=\"position:relative;\"><a href=\"#self-organised\" aria-label=\"self organised permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Self-organised</h2>\n<p>There is no right or wrong way to organise and hence sometimes teams fail. This attribute of the Agile development team gives freedom based on the maturity of the team to organise and plan the work for themselves. If in scrum team plans the daily work on their own. No one assigns the work.</p>\n<p>This helps in prevailing the high motivation, team members can better innovate and work towards the quality of deliverables. They can act without escalations without any unnecessary commands and control.</p>\n<h2 id=\"autonomy\" style=\"position:relative;\"><a href=\"#autonomy\" aria-label=\"autonomy permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Autonomy</h2>\n<p>This brings the sense of ownership, a mental state when the team feels the accountability of the results. Team members voluntarily take ownership and make themselves responsible for the results of the product and project deliveries. Team members collaborate, work together, learn and share the feedback with an open mind. Help each other and grow together.</p>\n<style class=\"grvsc-styles\">\n  .grvsc-container {\n    overflow: auto;\n    -webkit-overflow-scrolling: touch;\n    padding-top: 1rem;\n    padding-top: var(--grvsc-padding-top, var(--grvsc-padding-v, 1rem));\n    padding-bottom: 1rem;\n    padding-bottom: var(--grvsc-padding-bottom, var(--grvsc-padding-v, 1rem));\n    border-radius: 8px;\n    border-radius: var(--grvsc-border-radius, 8px);\n    font-feature-settings: normal;\n  }\n  \n  .grvsc-code {\n    display: inline-block;\n    min-width: 100%;\n  }\n  \n  .grvsc-line {\n    display: inline-block;\n    box-sizing: border-box;\n    width: 100%;\n    padding-left: 1.5rem;\n    padding-left: var(--grvsc-padding-left, var(--grvsc-padding-h, 1.5rem));\n    padding-right: 1.5rem;\n    padding-right: var(--grvsc-padding-right, var(--grvsc-padding-h, 1.5rem));\n  }\n  \n  .grvsc-line-highlighted {\n    background-color: var(--grvsc-line-highlighted-background-color, transparent);\n    box-shadow: inset var(--grvsc-line-highlighted-border-width, 4px) 0 0 0 var(--grvsc-line-highlighted-border-color, transparent);\n  }\n  \n</style>","frontmatter":{"date":"July 27, 2020","updated_date":null,"description":"Agile is becoming another SDLC methodology but in reality, it is beyond normal project management. With time It’s been accessorized a lot and leaving behind the basic building blocks and the important entity the Agile Development Teams.","title":"Qualities of an agile development team","tags":["Agile","Development","Teamwork"],"pinned":null,"coverImage":{"childImageSharp":{"fluid":{"aspectRatio":1.5037593984962405,"src":"/static/3e69292068b3c0327db542c1bc770f1c/58556/agile.webp","srcSet":"/static/3e69292068b3c0327db542c1bc770f1c/61e93/agile.webp 200w,\n/static/3e69292068b3c0327db542c1bc770f1c/1f5c5/agile.webp 400w,\n/static/3e69292068b3c0327db542c1bc770f1c/58556/agile.webp 800w,\n/static/3e69292068b3c0327db542c1bc770f1c/99238/agile.webp 1200w,\n/static/3e69292068b3c0327db542c1bc770f1c/7c22d/agile.webp 1600w,\n/static/3e69292068b3c0327db542c1bc770f1c/d4378/agile.webp 3600w","sizes":"(max-width: 800px) 100vw, 800px"}}},"author":{"id":"Vikram Jain","github":null,"avatar":null}}}},{"node":{"excerpt":"Digital Identity and IAM Domain have been the talk of the technology town for decades. There has been plenty of research, innovation, and…","fields":{"slug":"/engineering/difference-between-iam-ciam-and-idaas/"},"html":"<p>Digital Identity and IAM Domain have been the talk of the technology town for decades. There has been plenty of research, innovation, and information around these two, which led to many terminologies for the platforms providing the relevant features. Some of these terminologies are specific to the characteristics of the platform, while others are used interchangeably.</p>\n<p>In this article, let’s discuss the following commonly used terminologies for the platforms providing the relevant features:</p>\n<ul>\n<li>Identity and Access Management (IAM)</li>\n<li>Consumer Identity and Access Management (CIAM)</li>\n<li>Customer Identity and Access Management (CIAM)</li>\n<li>Identity Platform</li>\n<li>Identity Management (IdM)</li>\n<li>Identity as a Service (IDaaS)</li>\n<li>SaaS-delivered IAM</li>\n</ul>\n<p>These terminologies revolve around the IAM, CIAM, and IDaaS platforms. The infographic below categorizes these terminologies within these platforms:</p>\n<p><img src=\"/69f5d8fc6960a5d3d104150136659437/iam_ciam_idaas.webp\" alt=\"IAM CIAM and IDAAS Comparison\"></p>\n<h2 id=\"know-the-definition\" style=\"position:relative;\"><a href=\"#know-the-definition\" aria-label=\"know the definition permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Know the definition</h2>\n<p><strong>IAM</strong> defines and manages the roles and access privileges of network users and the cases in which users are granted or denied them. The primary purpose of IAM systems is one digital identity per individual. The established digital identity is then maintained, modified, and monitored throughout users' access lifecycles. </p>\n<p><strong>CIAM</strong> is a subset of the broader concept of identity access management (IAM). It explicitly focuses on managing customers' identities who need access to websites, web portals, and mobile apps.</p>\n<p><strong>IDaaS</strong> is an authentication infrastructure that is built, hosted, and managed by a third-party service provider. IDaaS companies supply cloud-based authentication or identity management to enterprises who subscribe. It allows enterprises to use single sign-on, authentication, and access controls to provide secure access to their growing number of software and SaaS applications.</p>\n<h2 id=\"iam-features-and-use-case\" style=\"position:relative;\"><a href=\"#iam-features-and-use-case\" aria-label=\"iam features and use case permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>IAM Features and Use Case</h2>\n<p>IAM is used for employee/internal-facing identity and access management solutions. The following explains a typical example of the IAM implementation within an organization:</p>\n<p>John, a new employee, joins the organization, and the application allows provisioning of his organizational identity. John can then login to his organization's portal, and based on the access configuration, he is either authorized or denied access to information or a resource.</p>\n<p>Besides, the organization has multiple portals, and John is allowed to access these portals using the same credentials. Throughout the job tenure, John's profile is maintained or updated from time to time. Eventually, when John decides to move on, deleting John's account from one portal revokes his access to all other portals.</p>\n<p><strong>IAM</strong> has the following four components:</p>\n<ul>\n<li><strong>Authentication</strong>:  A user provides credentials to gain initial access to an application or a particular resource. Upon user authentication, a session is created and referred during the interaction between user and application until the user logs off or session terminates.</li>\n<li><strong>Authorization</strong>: It is performed by checking the resource access request against authorization policies that are stored in an IAM policy store. It is the core area that implements the access controls based on data, including user attributes, user roles, business rules, etc.</li>\n<li><strong>User Management</strong>: It comprises Role Management, User Profile Management, User Activity Monitoring, User Provisioning, and deprovisioning.</li>\n<li><strong>Central User Repository</strong>: It stores and delivers identity information to other services. It usually comes with a data synchronization service to keep the data in synchronization with other identity sources.</li>\n</ul>\n<blockquote>\n<p>Organizations earlier used on-premises IAM software for identity and access management. Now the identity management process is getting more complicated as organizations add more cloud services to their environments. Thus, as a logical step, the organizations adopt cloud-based Identity-as-a-Service (IDaaS) and cloud IAM solutions.</p>\n</blockquote>\n<h2 id=\"ciam-features-and-use-case\" style=\"position:relative;\"><a href=\"#ciam-features-and-use-case\" aria-label=\"ciam features and use case permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>CIAM Features and Use Case</h2>\n<p>CIAM is used for customer-facing solutions. The capabilities of IAM are followed in the CIAM solutions; however, the use cases and requirements vary. Common features of CIAM include: </p>\n<ul>\n<li>Self-registration for customers, usually via social network registration </li>\n<li>Consent mechanisms for users to control the use of their data </li>\n<li>Single Sign-On (SSO) across all digital properties </li>\n<li>Multiple authentications options for customers, depending on risks and policies </li>\n<li>Customer profile storage </li>\n<li>SaaS application integration </li>\n<li>Fine-grained access control to resources and data</li>\n</ul>\n<p> The following explains a typical example of the CIAM implementation in a customer-facing application:</p>\n<p> Sarah, a new customer registers on the application. If applicable, the application should request for Sarah’s consent on business privacy policies and get her social profile data. The application must ensure the security and privacy of the captured data during registration, social login, or activities performed during her life cycle. Besides, Sarah should be allowed to manage access to her profile data and delete her account from the application. On the other hand, the business should be allowed to get insights on their customer to understand and deliver their needs.</p>\n<p> The core components of IAM remain the same across areas like authentication, authorization, user management, and central user repository. Thus, the need for Single Sign-On, Authentication Protocols, Access Management, Centralized and Universal Directories, User Lifecycle Management and Authorization, etc remains the same.</p>\n<blockquote>\n<p>It is a common misconception that the technology required for CIAM is the same for IAM. CIAM is far more challenging irrespective of the similarities with the IAM, and it is recommended to have a CIAM solution in place for your customers.</p>\n</blockquote>\n<h2 id=\"idaas-features-and-use-case\" style=\"position:relative;\"><a href=\"#idaas-features-and-use-case\" aria-label=\"idaas features and use case permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>IDaaS Features and Use Case</h2>\n<p>The enterprises typically use IDaaS to extend their existing IAM infrastructure. Thus, enterprise IDaaS providers must deploy solutions that can:</p>\n<ul>\n<li>Connect with existing user directories (like AD) for authentication.</li>\n<li>Provide role management to grant permissions and resource access to users.</li>\n<li>Enhance security by providing ways of defining security for critical applications.</li>\n</ul>\n<p>The following are the critical features of IDaaS:</p>\n<ul>\n<li><strong>Cloud-Based and Multitenant Architecture</strong>: To support the immediate issuing of updates, security fixes, and performance improvements to every enterprise customer.</li>\n<li><strong>Provisioning</strong>: To sync user data with web and enterprise applications through SCIM (system for cross-domain identity management) support and integration with on-premises provisioning.</li>\n<li><strong>Authentication</strong>: To incorporate necessary means of authentication such as multi-factor authentication via passwords, digital access cards, or biometrics.</li>\n<li>\n<p><strong>Single Sign-On (SSO) and Federation</strong>: SSO capability to allow users to authenticate themselves across multiple applications using the same credentials.</p>\n<p>Similarly, the federation capability allows the organizations to manage secure authentication for third-party cloud services accessed beyond the control of internal IT departments.</p>\n</li>\n<li><strong>Directory Service</strong>: To integrate IDaaS with enterprise existing user stores or a cloud directory.</li>\n<li><strong>Intelligence</strong>: To facilitate identity access log monitoring and reporting.</li>\n</ul>\n<blockquote>\n<p>The enterprises use several applications, mostly cloud-based services, while some of the applications hosted on-premise. Managing the credentials and access to each of those applications has become hectic.</p>\n</blockquote>\n<blockquote>\n<p>Since IDaaS provides a single point of user and access management for all the applications, granting or revoking access to users becomes very easy. Besides, it enables SSO to avoid managing separate login credentials for different service providers.</p>\n</blockquote>\n<p>If you are looking for information on more terminology around the platforms mentioned in this article, add your request in the comments below. I will either address them here or write another article dedicated to your requests and questions!</p>\n<style class=\"grvsc-styles\">\n  .grvsc-container {\n    overflow: auto;\n    -webkit-overflow-scrolling: touch;\n    padding-top: 1rem;\n    padding-top: var(--grvsc-padding-top, var(--grvsc-padding-v, 1rem));\n    padding-bottom: 1rem;\n    padding-bottom: var(--grvsc-padding-bottom, var(--grvsc-padding-v, 1rem));\n    border-radius: 8px;\n    border-radius: var(--grvsc-border-radius, 8px);\n    font-feature-settings: normal;\n  }\n  \n  .grvsc-code {\n    display: inline-block;\n    min-width: 100%;\n  }\n  \n  .grvsc-line {\n    display: inline-block;\n    box-sizing: border-box;\n    width: 100%;\n    padding-left: 1.5rem;\n    padding-left: var(--grvsc-padding-left, var(--grvsc-padding-h, 1.5rem));\n    padding-right: 1.5rem;\n    padding-right: var(--grvsc-padding-right, var(--grvsc-padding-h, 1.5rem));\n  }\n  \n  .grvsc-line-highlighted {\n    background-color: var(--grvsc-line-highlighted-background-color, transparent);\n    box-shadow: inset var(--grvsc-line-highlighted-border-width, 4px) 0 0 0 var(--grvsc-line-highlighted-border-color, transparent);\n  }\n  \n</style>","frontmatter":{"date":"July 24, 2020","updated_date":null,"description":"Over time, organizations are using many terminologies for IAM, CIAM, and IDaaS platforms. This article clarifies the use of these terms, key features, and common use cases of IAM, CIAM, and IDaaS platforms.","title":"IAM, CIAM, and IDaaS - know the difference and terms used for them","tags":["iam","ciam","idaas","identity"],"pinned":null,"coverImage":{"childImageSharp":{"fluid":{"aspectRatio":1.5037593984962405,"src":"/static/a5130bd86b66f92b9a0458e359a10100/58556/triplets.webp","srcSet":"/static/a5130bd86b66f92b9a0458e359a10100/61e93/triplets.webp 200w,\n/static/a5130bd86b66f92b9a0458e359a10100/1f5c5/triplets.webp 400w,\n/static/a5130bd86b66f92b9a0458e359a10100/58556/triplets.webp 800w,\n/static/a5130bd86b66f92b9a0458e359a10100/99238/triplets.webp 1200w,\n/static/a5130bd86b66f92b9a0458e359a10100/7c22d/triplets.webp 1600w","sizes":"(max-width: 800px) 100vw, 800px"}}},"author":{"id":"Archna Yadav","github":null,"avatar":null}}}},{"node":{"excerpt":"Logs are very helpful in finding the root cause of the issues you may be experiencing in an app. It is an efficient way to resolve issues by…","fields":{"slug":"/engineering/how-to-obtain-ios-application-logs-without-mac/"},"html":"<p>Logs are very helpful in finding the root cause of the issues you may be experiencing in an app. It is an efficient way to resolve issues by knowing the exact reason after checking Logs.</p>\n<p>Let's say we have developed an iOS app. As in many situations, we want to test our app on another's phone for many reasons. And probably that phone cannot be connected to the Mac. So, the console logs of the app can be sent directly from the app to the developer(us).</p>\n<p>This blog will provide step-by-step instructions for mailing iOS app logs directly from the app. </p>\n<h3 id=\"getting-started\" style=\"position:relative;\"><a href=\"#getting-started\" aria-label=\"getting started permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Getting started</h3>\n<p>Here we are having a <a href=\"https://github.com/tanvijn/TestLogs/tree/master\">project</a> with a single ViewController. We may ask our users to install the app on their device, use it and at the end click on “Press for Logs” Button. By clicking IBAction pressForLogs function will get called which will open MailComposer and then the user can mail the Log file to us.</p>\n<h3 id=\"steps-to-do-in-your-own-project\" style=\"position:relative;\"><a href=\"#steps-to-do-in-your-own-project\" aria-label=\"steps to do in your own project permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Steps to do in your own project</h3>\n<ul>\n<li>Find AppDelegate.swift in your project. Define following var and function as global before any import statement.</li>\n</ul>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"java\" data-index=\"0\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk4\">public</span><span class=\"mtk1\"> </span><span class=\"mtk4\">var</span><span class=\"mtk1\"> </span><span class=\"mtk12\">logFilePath</span><span class=\"mtk15\">:</span><span class=\"mtk1\">String!</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\"> </span></span>\n<span class=\"grvsc-line\"><span class=\"mtk3\">//======================//</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">func </span><span class=\"mtk11\">print</span><span class=\"mtk1\">(</span><span class=\"mtk10\">_</span><span class=\"mtk1\"> </span><span class=\"mtk12\">items</span><span class=\"mtk15\">:</span><span class=\"mtk1\"> </span><span class=\"mtk10\">Any</span><span class=\"mtk1\">..., separator</span><span class=\"mtk15\">:</span><span class=\"mtk1\"> String = </span><span class=\"mtk8\">&quot; &quot;</span><span class=\"mtk1\">, terminator</span><span class=\"mtk15\">:</span><span class=\"mtk1\"> String = </span><span class=\"mtk8\">&quot;</span><span class=\"mtk6\">\\n</span><span class=\"mtk8\">&quot;</span><span class=\"mtk1\">) {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    let output = </span><span class=\"mtk12\">items</span><span class=\"mtk1\">.</span><span class=\"mtk12\">map</span><span class=\"mtk1\"> { </span><span class=\"mtk8\">&quot;*</span><span class=\"mtk6\">\\(</span><span class=\"mtk8\">$0)&quot;</span><span class=\"mtk1\">}.</span><span class=\"mtk11\">joined</span><span class=\"mtk1\">(separator</span><span class=\"mtk15\">:</span><span class=\"mtk1\"> </span><span class=\"mtk8\">&quot; &quot;</span><span class=\"mtk1\">)</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk3\">//Swift.print(output, terminator: terminator)</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk11\">NSLog</span><span class=\"mtk1\">(output)</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">}</span></span></code></pre>\n<p> Above function override any log calls in the app.</p>\n<ul>\n<li>Then define the following method in AppDelegate.Swift file. And call from <code>func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool function.</code></li>\n</ul>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"swift\" data-index=\"1\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk4\">func</span><span class=\"mtk1\"> </span><span class=\"mtk11\">printTheDataAtLogFile</span><span class=\"mtk1\">() {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    logFilePath = </span><span class=\"mtk11\">NSTemporaryDirectory</span><span class=\"mtk1\">().</span><span class=\"mtk11\">appending</span><span class=\"mtk1\">(</span><span class=\"mtk10\">String</span><span class=\"mtk1\">.</span><span class=\"mtk4\">init</span><span class=\"mtk1\">(</span><span class=\"mtk11\">format</span><span class=\"mtk1\">: </span><span class=\"mtk8\">&quot;%@.log&quot;</span><span class=\"mtk1\">,Bundle.</span><span class=\"mtk12\">main</span><span class=\"mtk1\">.</span><span class=\"mtk11\">object</span><span class=\"mtk1\">(</span><span class=\"mtk11\">forInfoDictionaryKey</span><span class=\"mtk1\">: </span><span class=\"mtk8\">&quot;CFBundleName&quot;</span><span class=\"mtk1\">) as! </span><span class=\"mtk10\">String</span><span class=\"mtk1\">)) as </span><span class=\"mtk10\">String</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">       </span><span class=\"mtk11\">freopen</span><span class=\"mtk1\">((logFilePath as NSString).</span><span class=\"mtk11\">cString</span><span class=\"mtk1\">(</span><span class=\"mtk11\">using</span><span class=\"mtk1\">: </span><span class=\"mtk10\">String</span><span class=\"mtk1\">.</span><span class=\"mtk11\">Encoding</span><span class=\"mtk1\">(</span><span class=\"mtk11\">rawValue</span><span class=\"mtk1\">: </span><span class=\"mtk10\">String</span><span class=\"mtk1\">.</span><span class=\"mtk12\">Encoding</span><span class=\"mtk1\">.</span><span class=\"mtk12\">ascii</span><span class=\"mtk1\">.</span><span class=\"mtk12\">rawValue</span><span class=\"mtk1\">).</span><span class=\"mtk12\">rawValue</span><span class=\"mtk1\">)!, </span><span class=\"mtk8\">&quot;a+&quot;</span><span class=\"mtk1\">, stderr)</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">   }</span></span></code></pre>\n<p>Above function will write all logs into a file instead of console.</p>\n<ul>\n<li>\n<p>Open Viewcontroller.swift. Define below 2 functions in it. </p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"swift\" data-index=\"2\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk4\">func</span><span class=\"mtk1\"> </span><span class=\"mtk11\">allOptions</span><span class=\"mtk1\">() {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk4\">let</span><span class=\"mtk1\"> alert = </span><span class=\"mtk11\">UIAlertController</span><span class=\"mtk1\">(</span><span class=\"mtk11\">title</span><span class=\"mtk1\">: </span><span class=\"mtk8\">&quot;Please Select an Option&quot;</span><span class=\"mtk1\">, </span><span class=\"mtk11\">message</span><span class=\"mtk1\">: </span><span class=\"mtk4\">nil</span><span class=\"mtk1\">, </span><span class=\"mtk11\">preferredStyle</span><span class=\"mtk1\">: .</span><span class=\"mtk12\">actionSheet</span><span class=\"mtk1\">)</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">alert.</span><span class=\"mtk11\">addAction</span><span class=\"mtk1\">(</span><span class=\"mtk11\">UIAlertAction</span><span class=\"mtk1\">(</span><span class=\"mtk11\">title</span><span class=\"mtk1\">: </span><span class=\"mtk8\">&quot;Log Mail&quot;</span><span class=\"mtk1\">, </span><span class=\"mtk11\">style</span><span class=\"mtk1\">: .</span><span class=\"mtk12\">default</span><span class=\"mtk1\"> , </span><span class=\"mtk11\">handler</span><span class=\"mtk1\">:{ (UIAlertAction)</span><span class=\"mtk15\">in</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk4\">self</span><span class=\"mtk1\">.</span><span class=\"mtk11\">shareDocument</span><span class=\"mtk1\">(</span><span class=\"mtk11\">documentPath</span><span class=\"mtk1\">: logFilePath)</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">}))</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">alert.</span><span class=\"mtk11\">addAction</span><span class=\"mtk1\">(</span><span class=\"mtk11\">UIAlertAction</span><span class=\"mtk1\">(</span><span class=\"mtk11\">title</span><span class=\"mtk1\">: </span><span class=\"mtk8\">&quot;dismis&quot;</span><span class=\"mtk1\">, </span><span class=\"mtk11\">style</span><span class=\"mtk1\">: .</span><span class=\"mtk12\">cancel</span><span class=\"mtk1\">, </span><span class=\"mtk11\">handler</span><span class=\"mtk1\">:{ (UIAlertAction)</span><span class=\"mtk15\">in</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk11\">print</span><span class=\"mtk1\">(</span><span class=\"mtk8\">&quot;User click Dismiss button&quot;</span><span class=\"mtk1\">)</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">}))</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk4\">self</span><span class=\"mtk1\">.</span><span class=\"mtk11\">present</span><span class=\"mtk1\">(alert, </span><span class=\"mtk11\">animated</span><span class=\"mtk1\">: </span><span class=\"mtk4\">true</span><span class=\"mtk1\">, </span><span class=\"mtk11\">completion</span><span class=\"mtk1\">: {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk11\">print</span><span class=\"mtk1\">(</span><span class=\"mtk8\">&quot;completion block&quot;</span><span class=\"mtk1\">)</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">})</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">}</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk3\">//  ============================= //</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk3\">// this is to share file //</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk4\">func</span><span class=\"mtk1\"> </span><span class=\"mtk11\">shareDocument</span><span class=\"mtk1\">(</span><span class=\"mtk11\">documentPath</span><span class=\"mtk1\">: </span><span class=\"mtk10\">String</span><span class=\"mtk1\">) {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk15\">if</span><span class=\"mtk1\"> FileManager.</span><span class=\"mtk12\">default</span><span class=\"mtk1\">.</span><span class=\"mtk11\">fileExists</span><span class=\"mtk1\">(</span><span class=\"mtk11\">atPath</span><span class=\"mtk1\">: documentPath){</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  </span><span class=\"mtk4\">let</span><span class=\"mtk1\"> fileURL = </span><span class=\"mtk11\">URL</span><span class=\"mtk1\">(</span><span class=\"mtk11\">fileURLWithPath</span><span class=\"mtk1\">: documentPath)</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  </span><span class=\"mtk4\">let</span><span class=\"mtk1\"> activityViewController: UIActivityViewController = </span><span class=\"mtk11\">UIActivityViewController</span><span class=\"mtk1\">(</span><span class=\"mtk11\">activityItems</span><span class=\"mtk1\">: [fileURL], </span><span class=\"mtk11\">applicationActivities</span><span class=\"mtk1\">: </span><span class=\"mtk4\">nil</span><span class=\"mtk1\">)</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  activityViewController.</span><span class=\"mtk12\">popoverPresentationController</span><span class=\"mtk1\">?.</span><span class=\"mtk12\">sourceView</span><span class=\"mtk1\">=</span><span class=\"mtk4\">self</span><span class=\"mtk1\">.</span><span class=\"mtk12\">view</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  </span><span class=\"mtk11\">present</span><span class=\"mtk1\">(activityViewController, </span><span class=\"mtk11\">animated</span><span class=\"mtk1\">: </span><span class=\"mtk4\">true</span><span class=\"mtk1\">, </span><span class=\"mtk11\">completion</span><span class=\"mtk1\">: </span><span class=\"mtk4\">nil</span><span class=\"mtk1\">)</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">}</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk15\">else</span><span class=\"mtk1\"> {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  </span><span class=\"mtk11\">print</span><span class=\"mtk1\">(</span><span class=\"mtk8\">&quot;Document was not found&quot;</span><span class=\"mtk1\">)</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">}</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">}</span></span></code></pre>\n<p>Call <code>allOptions()</code> from IBAction pressForLogs. Above functions will open ActivityViewContrrolle to let the user mail log file to you.</p>\n</li>\n</ul>\n<h4 id=\"voila-\" style=\"position:relative;\"><a href=\"#voila-\" aria-label=\"voila  permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Voila!! :)</h4>\n<p>Thanks for visiting us! We hope you find this knowledge base useful! Our mission is to make mobile app development happy. We hope we’re living up to the mission with your project.</p>\n<p>Please write to us for suggestions and for the contents we should come up with!</p>\n<p>Thanks for reading the blog. For detailed information and execution example of this blog, please refer to the video below:</p>\n<iframe width=\"560\" height=\"315\" src=\"https://www.youtube.com/embed/KTnFtIvoDiI\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen></iframe>\n<style class=\"grvsc-styles\">\n  .grvsc-container {\n    overflow: auto;\n    -webkit-overflow-scrolling: touch;\n    padding-top: 1rem;\n    padding-top: var(--grvsc-padding-top, var(--grvsc-padding-v, 1rem));\n    padding-bottom: 1rem;\n    padding-bottom: var(--grvsc-padding-bottom, var(--grvsc-padding-v, 1rem));\n    border-radius: 8px;\n    border-radius: var(--grvsc-border-radius, 8px);\n    font-feature-settings: normal;\n  }\n  \n  .grvsc-code {\n    display: inline-block;\n    min-width: 100%;\n  }\n  \n  .grvsc-line {\n    display: inline-block;\n    box-sizing: border-box;\n    width: 100%;\n    padding-left: 1.5rem;\n    padding-left: var(--grvsc-padding-left, var(--grvsc-padding-h, 1.5rem));\n    padding-right: 1.5rem;\n    padding-right: var(--grvsc-padding-right, var(--grvsc-padding-h, 1.5rem));\n  }\n  \n  .grvsc-line-highlighted {\n    background-color: var(--grvsc-line-highlighted-background-color, transparent);\n    box-shadow: inset var(--grvsc-line-highlighted-border-width, 4px) 0 0 0 var(--grvsc-line-highlighted-border-color, transparent);\n  }\n  \n  .dark-default-dark {\n    background-color: #1E1E1E;\n    color: #D4D4D4;\n  }\n  .dark-default-dark .mtk4 { color: #569CD6; }\n  .dark-default-dark .mtk1 { color: #D4D4D4; }\n  .dark-default-dark .mtk12 { color: #9CDCFE; }\n  .dark-default-dark .mtk15 { color: #C586C0; }\n  .dark-default-dark .mtk3 { color: #6A9955; }\n  .dark-default-dark .mtk11 { color: #DCDCAA; }\n  .dark-default-dark .mtk10 { color: #4EC9B0; }\n  .dark-default-dark .mtk8 { color: #CE9178; }\n  .dark-default-dark .mtk6 { color: #D7BA7D; }\n</style>","frontmatter":{"date":"July 22, 2020","updated_date":null,"description":null,"title":"How to obtain iOS application logs without Mac","tags":["Logs","ios","xcode","iPhone","troubleshoot","Mac"],"pinned":null,"coverImage":{"childImageSharp":{"fluid":{"aspectRatio":1.5037593984962405,"src":"/static/4fdc8a84c6075fd3dd77f0b0be3f1939/58556/Log.webp","srcSet":"/static/4fdc8a84c6075fd3dd77f0b0be3f1939/61e93/Log.webp 200w,\n/static/4fdc8a84c6075fd3dd77f0b0be3f1939/1f5c5/Log.webp 400w,\n/static/4fdc8a84c6075fd3dd77f0b0be3f1939/58556/Log.webp 800w,\n/static/4fdc8a84c6075fd3dd77f0b0be3f1939/99238/Log.webp 1200w,\n/static/4fdc8a84c6075fd3dd77f0b0be3f1939/90fb1/Log.webp 1500w","sizes":"(max-width: 800px) 100vw, 800px"}}},"author":{"id":"Tanvi Jain","github":"tanvijn","avatar":null}}}},{"node":{"excerpt":"What is the “hosts” file A hosts file which is used by operating systems to map a connection between an IP address and domain names before…","fields":{"slug":"/engineering/hosts-file/"},"html":"<h2 id=\"what-is-the-hosts-file\" style=\"position:relative;\"><a href=\"#what-is-the-hosts-file\" aria-label=\"what is the hosts file permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>What is the “hosts” file</h2>\n<p>A hosts file which is used by operating systems to map a connection between an IP address and domain names before going to domain name servers. This file is a simple text file with the mapping of IPs and domain names.</p>\n<h3 id=\"lets-talk-about-the-usage-of-the-hosts-file\" style=\"position:relative;\"><a href=\"#lets-talk-about-the-usage-of-the-hosts-file\" aria-label=\"lets talk about the usage of the hosts file permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Let’s talk about the usage of the hosts file</h3>\n<h5 id=\"protecting-privacy\" style=\"position:relative;\"><a href=\"#protecting-privacy\" aria-label=\"protecting privacy permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Protecting Privacy</h5>\n<p>You can use this to block advertisers, trackers, block marketing, or third party websites, block ads, banners, 3rd party page counters, or sites to protect your privacy. </p>\n<h5 id=\"block-website-for-your-kids\" style=\"position:relative;\"><a href=\"#block-website-for-your-kids\" aria-label=\"block website for your kids permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Block website for your kids</h5>\n<p>If you don’t want your children to open some websites you can block them by the hosts file. You can decide entirely what you wish to block and even most hijackers and possibly unwanted programs. </p>\n<h5 id=\"security\" style=\"position:relative;\"><a href=\"#security\" aria-label=\"security permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Security</h5>\n<p>We can utilize it as a firewall in our local system. The hosts file is to block Spyware and/or ad Networks you can add all the Spyware sites &#x26; ad Networks domain names in your hosts file also you can block dangerous sites, ransomware sites, blockchain sites. </p>\n<h5 id=\"development\" style=\"position:relative;\"><a href=\"#development\" aria-label=\"development permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Development</h5>\n<p>You know during the development, you need to run your web application on the localhost for verification. Websites can run on the localhost, 127.0.0.1, or localhost IP address. There are some limitations in the localhost, you want to review your website on the custom domain before launching on the public domain suppose you have developed the e-commerce. You want to debug some payment gateway issue but your payment gateway is not supporting localhost URL or IP in the case of successful payment. You can add custom domain in the hosts file and validate the payment process on localhost </p>\n<h4 id=\"how-to-edit-hosts-file\" style=\"position:relative;\"><a href=\"#how-to-edit-hosts-file\" aria-label=\"how to edit hosts file permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>How to edit hosts file</h4>\n<h5 id=\"windows-8-or-10\" style=\"position:relative;\"><a href=\"#windows-8-or-10\" aria-label=\"windows 8 or 10 permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Windows 8 or 10</h5>\n<p>Windows operating system we need to open the host file </p>\n<ol>\n<li>Go to the Start menu and start typing the Notepad.</li>\n<li>Right-click Notepad and choose Run as administrator</li>\n</ol>\n<p>  <img src=\"/20915351d9e41e6e17b66f533f7db315/windows1.webp\" alt=\"Start Menu\"></p>\n<ol start=\"3\">\n<li>\n<p>Open the hosts file. Click on File > Open and Copy and Paste the following path`</p>\n<p><code>c:\\Windows\\System32\\Drivers\\etc\\hosts</code></p>\n</li>\n</ol>\n<p>  <img src=\"/a52d88025ba356b78b68017472da1df7/windows2.webp\" alt=\"edit-hosts-file-windows\"></p>\n<p>You can edit the hosts file</p>\n<p>Suppose you want to block facebook.com on your system and want to add a custom domain for your website. Just Copy and Paste following Lines</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"0\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">0.0.0.0         www.facebook.com</span>\n<span class=\"grvsc-line\">127.0.0.1       www.customdomain.com</span></code></pre>\n<p>  <img src=\"/3074615f157eeced9b2f4894885241dd/windows3.webp\" alt=\"Save-hosts-file-windows\"></p>\n<p>After finishing the Editing, <strong>Save your hosts file</strong></p>\n<p>  <img src=\"/ead0cbcf828255f6f85c0fe51ebabff0/windows4.webp\" alt=\"Save-hosts-file-windows\"></p>\n<p>Open your browser and try to access www.facebook.com and see you can’t access this site</p>\n<p>  <img src=\"/220ec47e648a76dc4f5fb2e09725d9cf/windows5.webp\" alt=\"Facebook-windows\"></p>\n<h5 id=\"linux\" style=\"position:relative;\"><a href=\"#linux\" aria-label=\"linux permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Linux</h5>\n<p>Use following instructions for Linux </p>\n<ol>\n<li>\n<p>In the Linux terminal window, open hosts file using a favorite text editor </p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"1\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">$ sudo vim /etc/hosts</span></code></pre>\n</li>\n</ol>\n<p>  <img src=\"/3095554fa34ec943f59ec582c335a595/linux1.webp\" alt=\"linux-hosts-file\"></p>\n<p>  It will prompt for the password, enter your administrator password.</p>\n<ol start=\"2\">\n<li>Using the vim or your favorite text editor you can easily edit. The Linux hosts file is similar to the windows hosts file. Now again I am blocking Facebook and adding a custom domain </li>\n</ol>\n<p>  <img src=\"/0a619c3369d143ad0fdc5e2c64eb80e0/linux2.webp\" alt=\"linux-hosts-file-edit\"></p>\n<ol start=\"3\">\n<li>Save the Changes</li>\n</ol>\n<h5 id=\"mac-os\" style=\"position:relative;\"><a href=\"#mac-os\" aria-label=\"mac os permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Mac OS</h5>\n<p>Use following instructions for macOS </p>\n<ol>\n<li>Find the terminal application on your system\n-- We can use Spotlight application to search </li>\n</ol>\n<p>  <img src=\"/e0b8a6efe1386a10aa3419333583826c/mac1.webp\" alt=\"linux-hosts-file-edit\"></p>\n<ol start=\"2\">\n<li>Type <code>sudo vim /etc/hosts</code> in the terminal\n-- It will prompt for the password, enter your administrator password\n-- Enter administrator Password\n</li>\n</ol>\n<p>  <img src=\"/f6ba574fac85962782fddd1d5ea01009/mac2.webp\" alt=\"mac-password\"></p>\n<p><em>Using the vim text editor you can easily edit you. The macOS hosts file is also similar to the windows and Linux hosts file. I am blocking Facebook and adding custom domain here as well</em>.</p>\n<p>  <img src=\"/ca8db5b6c7015e56d24e0eab54598b77/mac3.webp\" alt=\"mac-hosts-file-edit\"></p>\n<ol start=\"3\">\n<li>Save Changes\nOpen your browser and try to access www.facebook.com and see you can’t access this site.</li>\n</ol>\n<p>  <img src=\"/220ec47e648a76dc4f5fb2e09725d9cf/mac4.webp\" alt=\"edit-hosts-file-mac\"></p>\n<h3 id=\"conclusion\" style=\"position:relative;\"><a href=\"#conclusion\" aria-label=\"conclusion permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Conclusion</h3>\n<p>The hosts file is found on all operating systems. The hosts file is a powerful tool. It can make your computer more secure and safer by blocking malicious sites    </p>\n<style class=\"grvsc-styles\">\n  .grvsc-container {\n    overflow: auto;\n    -webkit-overflow-scrolling: touch;\n    padding-top: 1rem;\n    padding-top: var(--grvsc-padding-top, var(--grvsc-padding-v, 1rem));\n    padding-bottom: 1rem;\n    padding-bottom: var(--grvsc-padding-bottom, var(--grvsc-padding-v, 1rem));\n    border-radius: 8px;\n    border-radius: var(--grvsc-border-radius, 8px);\n    font-feature-settings: normal;\n  }\n  \n  .grvsc-code {\n    display: inline-block;\n    min-width: 100%;\n  }\n  \n  .grvsc-line {\n    display: inline-block;\n    box-sizing: border-box;\n    width: 100%;\n    padding-left: 1.5rem;\n    padding-left: var(--grvsc-padding-left, var(--grvsc-padding-h, 1.5rem));\n    padding-right: 1.5rem;\n    padding-right: var(--grvsc-padding-right, var(--grvsc-padding-h, 1.5rem));\n  }\n  \n  .grvsc-line-highlighted {\n    background-color: var(--grvsc-line-highlighted-background-color, transparent);\n    box-shadow: inset var(--grvsc-line-highlighted-border-width, 4px) 0 0 0 var(--grvsc-line-highlighted-border-color, transparent);\n  }\n  \n  .dark-default-dark {\n    background-color: #1E1E1E;\n    color: #D4D4D4;\n  }\n</style>","frontmatter":{"date":"July 20, 2020","updated_date":null,"description":"Hosts file maps hostnames to IP addresses, sometimes required to be edited either to block some sites or to test some custom domain.This blog explains how can we edit the hosts in different operating systems.","title":"Benefits and usages of Hosts File","tags":["Computer tricks","Networking","Hosts File"],"pinned":null,"coverImage":{"childImageSharp":{"fluid":{"aspectRatio":1.4184397163120568,"src":"/static/54b234435c9e01dc08a3d668cceb489e/991d2/index.webp","srcSet":"/static/54b234435c9e01dc08a3d668cceb489e/61e93/index.webp 200w,\n/static/54b234435c9e01dc08a3d668cceb489e/1f5c5/index.webp 400w,\n/static/54b234435c9e01dc08a3d668cceb489e/991d2/index.webp 640w","sizes":"(max-width: 640px) 100vw, 640px"}}},"author":{"id":"Vijay Singh Shekhawat","github":"code-vj","avatar":null}}}},{"node":{"excerpt":"Biggest Challenge in React application is the management of state for frontend developers. In large applications, React alone is not…","fields":{"slug":"/engineering/react-state-management/"},"html":"<p>Biggest Challenge in React application is the management of state for frontend developers. In large applications, React alone is not sufficient to handle the complexity which is why some developers use React hooks and others use state management libraries such as Redux.</p>\n<p>In this post, We are going to take a closer look at both React hooks and Redux to manage the state.</p>\n<h2 id=\"what-is-react-state-management\" style=\"position:relative;\"><a href=\"#what-is-react-state-management\" aria-label=\"what is react state management permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>What is React State Management?</h2>\n<p>React components have a built-in state object. The state is encapsulated data where you store assets that are persistent between component renderings.</p>\n<p>The state is just a fancy term for a JavaScript data structure. If a user changes state by interacting with your application, the UI may look completely different afterwards, because it's represented by this new state rather than the old state.</p>\n<blockquote>\n<p><strong>Make a state variable responsible for one concern to use efficiently</strong>.</p>\n</blockquote>\n<h2 id=\"why-do-you-need-react-state-management\" style=\"position:relative;\"><a href=\"#why-do-you-need-react-state-management\" aria-label=\"why do you need react state management permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Why do you need React state management?</h2>\n<p>React applications are built using components and they manage their state internally and it works well for applications with few components, but when the application grows bigger, the complexity of managing states shared across components becomes difficult.</p>\n<p>Here is a simple example of an e-commerce application, in which the status of multiple components will change when purchasing a product.</p>\n<ul>\n<li>Add that product to the shopping list</li>\n<li>Add product to customer history</li>\n<li>trigger count of purchased products</li>\n</ul>\n<p>If developers do not have scalability in mind then it is really hard to find out what is happening when something goes wrong. This is why you need state management in your application.</p>\n<p>Let’s discuss how to use react state management using react hooks and redux</p>\n<h2 id=\"what-is-redux\" style=\"position:relative;\"><a href=\"#what-is-redux\" aria-label=\"what is redux permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>What is Redux?</h2>\n<p>Redux was created to resolve this particular issue. it provides a central store that holds all states of your application. Each component can access the stored state without sending it from one component to another.  Here is a simple view of how Redux works.</p>\n<p><img src=\"/eb3f323b755c13f5139032d257d126fc/image1.webp\" alt=\"using react state management with redux flowchart\"></p>\n<p>There are three building parts: actions, store, and reducers. Let’s briefly discuss what each of them does.</p>\n<h4 id=\"actions-in-redux\" style=\"position:relative;\"><a href=\"#actions-in-redux\" aria-label=\"actions in redux permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Actions in Redux</h4>\n<p>Actions are payloads of information that send data from your application to your store. Actions are sent using  <a href=\"https://redux.js.org/api/store#dispatchaction\"><code>store.dispatch()</code></a>. Actions are created via an action creator.\nHere is an example action that represents adding a new todo item:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"0\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">{ </span>\n<span class=\"grvsc-line\">type: &quot;ADD_TODO&quot;, </span>\n<span class=\"grvsc-line\">payload: {text:&quot;Hello Foo&quot;}</span>\n<span class=\"grvsc-line\"> }</span></code></pre>\n<p>Here is an example of its action creator:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"1\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">ocnst addTodo = (text) =&gt; {</span>\n<span class=\"grvsc-line\">  return {</span>\n<span class=\"grvsc-line\">     type: &quot;ADD_TODO&quot;,</span>\n<span class=\"grvsc-line\">     text</span>\n<span class=\"grvsc-line\">  };</span>\n<span class=\"grvsc-line\">}</span></code></pre>\n<h4 id=\"reducers-in-redux\" style=\"position:relative;\"><a href=\"#reducers-in-redux\" aria-label=\"reducers in redux permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Reducers in Redux</h4>\n<p>Reducers specify how the application's state changes in response to actions sent to the store.\nAn example of how Reducer works in Redux is as follows:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"2\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">  const TODOReducer= (state = {}, action) =&gt; {</span>\n<span class=\"grvsc-line\">  switch (action.type) {</span>\n<span class=\"grvsc-line\">    case &quot;ADD_TODO&quot;:</span>\n<span class=\"grvsc-line\">      return {</span>\n<span class=\"grvsc-line\">        ...state,</span>\n<span class=\"grvsc-line\">        ...action.payload</span>\n<span class=\"grvsc-line\">      };</span>\n<span class=\"grvsc-line\">    default:</span>\n<span class=\"grvsc-line\">      return state;</span>\n<span class=\"grvsc-line\">  }</span>\n<span class=\"grvsc-line\">};</span></code></pre>\n<h4 id=\"store-in-redux\" style=\"position:relative;\"><a href=\"#store-in-redux\" aria-label=\"store in redux permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Store in Redux</h4>\n<p>The store holds the application state. You can access stored state, update the state, and register or unregister listeners via helper methods.</p>\n<p>Let’s create a store for our TODO app:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"3\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">const store = createStore(TODOReducer);</span></code></pre>\n<p>In other words, Redux gives you code organization and debugging superpowers. This makes it easier to build more maintainable code, and much easier to track down the root cause when something goes wrong.</p>\n<h2 id=\"what-is-react-hook\" style=\"position:relative;\"><a href=\"#what-is-react-hook\" aria-label=\"what is react hook permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>What is React Hook?</h2>\n<p>These are functions that hook you into React state and features from function components. Hooks don't work inside classes  and it allows you to use React features without writing a class. </p>\n<p>Hooks are backwards-compatible, which means it doesn't keep any breaking changes. <a href=\"/react-hooks-guide/\">React provides some built-in Hooks</a> like <code>useState</code>, <code>UseEffect</code> and <code>useReducer</code> etc. You can also make custom hooks.</p>\n<h3 id=\"react-hook-rules\" style=\"position:relative;\"><a href=\"#react-hook-rules\" aria-label=\"react hook rules permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>React Hook Rules</h3>\n<ul>\n<li>Call hook at the top level only means that you need to call inside a loop, nested function, or conditions.</li>\n<li>React function components are called hooks only.</li>\n</ul>\n<p>Please see the following examples of some react hooks as follows:</p>\n<h5 id=\"what-is-usestate-and-how-to--use-it\" style=\"position:relative;\"><a href=\"#what-is-usestate-and-how-to--use-it\" aria-label=\"what is usestate and how to  use it permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>What is useState and how to  use it</h5>\n<p><code>useState</code> is a Hook that Lets you add React state to function components.\nExample:\nDeclaring a State Variable in class and initialize count state with 0 by setting this.state  to {count:0}.</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"4\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">class Example extends React.Component {</span>\n<span class=\"grvsc-line\">  constructor(props) {</span>\n<span class=\"grvsc-line\">    super(props);</span>\n<span class=\"grvsc-line\">    this.state = {</span>\n<span class=\"grvsc-line\">      count: 0</span>\n<span class=\"grvsc-line\">    };</span>\n<span class=\"grvsc-line\">  }</span>\n<span class=\"grvsc-line\">  </span></code></pre>\n<p>In a function component, we have no this, so we can’t assign or read this.state. Instead, we call the <code>useState</code> Hook directly inside our component:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"5\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">function Example() {</span>\n<span class=\"grvsc-line\">    const [count, setCount] = useState(0);</span>\n<span class=\"grvsc-line\">}</span></code></pre>\n<p>We declare a state variable called count and set it to 0. React will remember its current value between re-renders, and provide the most recent one to our function. If we want to update the current count, we can call setCount.</p>\n<h5 id=\"what-is-usereducer-and-how-to-use-it\" style=\"position:relative;\"><a href=\"#what-is-usereducer-and-how-to-use-it\" aria-label=\"what is usereducer and how to use it permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>what is useReducer and how to use it</h5>\n<p><code>useReducer</code> is a hook I use sometimes to manage the state of the application. It is very similar to the <em>useState</em> hook, just more complex. <em>useReducer</em> hook uses the same concept as the reducers in Redux. It is basically a pure function, with no side-effects.</p>\n<p>Example of useReducer:</p>\n<p>useReducer creates an independent component co-located state container within your component. Whereas Redux creates a global state container that hangs somewhere above your entire application.</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"6\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">          +----------------+              +----------------+</span>\n<span class=\"grvsc-line\">          |  Component A   |              |                |</span>\n<span class=\"grvsc-line\">          |                |              |                |</span>\n<span class=\"grvsc-line\">          |                |              |      Redux     |</span>\n<span class=\"grvsc-line\">          +----------------+              |                |</span>\n<span class=\"grvsc-line\">          | connect Redux  |&lt;-------------|                |</span>\n<span class=\"grvsc-line\">          +--------+-------+              +--------+-------+</span>\n<span class=\"grvsc-line\">                   |                               |</span>\n<span class=\"grvsc-line\">         +---------+-----------+                   |</span>\n<span class=\"grvsc-line\">         |                     |                   |</span>\n<span class=\"grvsc-line\">         |                     |                   |</span>\n<span class=\"grvsc-line\">+--------+-------+    +--------+-------+           |</span>\n<span class=\"grvsc-line\">|  Component B   |    |  Component C   |           |</span>\n<span class=\"grvsc-line\">|                |    |                |           |</span>\n<span class=\"grvsc-line\">|                |    |                |           |</span>\n<span class=\"grvsc-line\">+----------------+    +----------------+           |</span>\n<span class=\"grvsc-line\">|    useReducer  |    | connect Redux  |&lt;----------+</span>\n<span class=\"grvsc-line\">+----------------+    +--------+-------+</span>\n<span class=\"grvsc-line\">                               |</span>\n<span class=\"grvsc-line\">                      +--------+-------+</span>\n<span class=\"grvsc-line\">                      |  Component D   |</span>\n<span class=\"grvsc-line\">                      |                |</span>\n<span class=\"grvsc-line\">                      |                |</span>\n<span class=\"grvsc-line\">                      +----------------+</span></code></pre>\n<p>Below an example of todo items is completed or not using the useReducer react hook.</p>\n<p>See the following function which  is a reducer function for managing state transitions for a list of items:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"7\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"> const todoReducer = (state, action) =&gt; {</span>\n<span class=\"grvsc-line\">      switch (action.type) {</span>\n<span class=\"grvsc-line\">        case &quot;ADD_TODO&quot;:</span>\n<span class=\"grvsc-line\">          return state.map(todo =&gt; {</span>\n<span class=\"grvsc-line\">            if (todo.id === action.id) {</span>\n<span class=\"grvsc-line\">              return { ...todo, complete: true };</span>\n<span class=\"grvsc-line\">            } else {</span>\n<span class=\"grvsc-line\">              return todo;</span>\n<span class=\"grvsc-line\">            }</span>\n<span class=\"grvsc-line\">          });</span>\n<span class=\"grvsc-line\">        case &quot;REMOVE_TODO&quot;:</span>\n<span class=\"grvsc-line\">          return state.map(todo =&gt; {</span>\n<span class=\"grvsc-line\">            if (todo.id === action.id) {</span>\n<span class=\"grvsc-line\">              return { ...todo, complete: false };</span>\n<span class=\"grvsc-line\">            } else {</span>\n<span class=\"grvsc-line\">              return todo;</span>\n<span class=\"grvsc-line\">            }</span>\n<span class=\"grvsc-line\">          });</span>\n<span class=\"grvsc-line\">        default:</span>\n<span class=\"grvsc-line\">          return state;</span>\n<span class=\"grvsc-line\">      }</span>\n<span class=\"grvsc-line\">    };</span></code></pre>\n<p>There are two types of actions which are equivalent to two states. they used to toggle the complete boolean field and additional payload to identify incoming action.</p>\n<p>The state which is managed in this reducer is an array of items:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"8\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">const initialTodos = [</span>\n<span class=\"grvsc-line\">      {</span>\n<span class=\"grvsc-line\">        id: &quot;t1&quot;,</span>\n<span class=\"grvsc-line\">        task: &quot;Add Task 1&quot;,</span>\n<span class=\"grvsc-line\">        complete: false</span>\n<span class=\"grvsc-line\">      },</span>\n<span class=\"grvsc-line\">      {</span>\n<span class=\"grvsc-line\">        id: &quot;t2&quot;,</span>\n<span class=\"grvsc-line\">        task: &quot;Add Task 2&quot;,</span>\n<span class=\"grvsc-line\">        complete: false</span>\n<span class=\"grvsc-line\">      }</span>\n<span class=\"grvsc-line\">    ];</span></code></pre>\n<p>In code, The useReducer hook is used for complex state and state transitions. It takes a reducer function and an initial state as input and returns the current state and a dispatch function as output</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"9\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"> const [todos, dispatch] = React.useReducer(</span>\n<span class=\"grvsc-line\">    todoReducer,</span>\n<span class=\"grvsc-line\">    initialTodos</span>\n<span class=\"grvsc-line\">  );</span></code></pre>\n<p>Complete file:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"10\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">import React from &quot;react&quot;;</span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\">const initialTodos = [</span>\n<span class=\"grvsc-line\">  {</span>\n<span class=\"grvsc-line\">    id: &quot;t1&quot;,</span>\n<span class=\"grvsc-line\">    task: &quot;Add Task 1&quot;,</span>\n<span class=\"grvsc-line\">    complete: false</span>\n<span class=\"grvsc-line\">  },</span>\n<span class=\"grvsc-line\">  {</span>\n<span class=\"grvsc-line\">    id: &quot;t2&quot;,</span>\n<span class=\"grvsc-line\">    task: &quot;Add Task 2&quot;,</span>\n<span class=\"grvsc-line\">    complete: false</span>\n<span class=\"grvsc-line\">  }</span>\n<span class=\"grvsc-line\">];</span>\n<span class=\"grvsc-line\">const todoReducer = (state, action) =&gt; {</span>\n<span class=\"grvsc-line\">  switch (action.type) {</span>\n<span class=\"grvsc-line\">    case &quot;ADD_TODO&quot;:</span>\n<span class=\"grvsc-line\">      return state.map(todo =&gt; {</span>\n<span class=\"grvsc-line\">        if (todo.id === action.id) {</span>\n<span class=\"grvsc-line\">          return { ...todo, complete: true };</span>\n<span class=\"grvsc-line\">        } else {</span>\n<span class=\"grvsc-line\">          return todo;</span>\n<span class=\"grvsc-line\">        }</span>\n<span class=\"grvsc-line\">      });</span>\n<span class=\"grvsc-line\">    case &quot;REMOVE_TODO&quot;:</span>\n<span class=\"grvsc-line\">      return state.map(todo =&gt; {</span>\n<span class=\"grvsc-line\">        if (todo.id === action.id) {</span>\n<span class=\"grvsc-line\">          return { ...todo, complete: false };</span>\n<span class=\"grvsc-line\">        } else {</span>\n<span class=\"grvsc-line\">          return todo;</span>\n<span class=\"grvsc-line\">        }</span>\n<span class=\"grvsc-line\">      });</span>\n<span class=\"grvsc-line\">    default:</span>\n<span class=\"grvsc-line\">      return state;</span>\n<span class=\"grvsc-line\">  }</span>\n<span class=\"grvsc-line\">};</span>\n<span class=\"grvsc-line\">const App = () =&gt; {</span>\n<span class=\"grvsc-line\">  const [todos, dispatch] = React.useReducer(todoReducer, initialTodos);</span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\">  const handleChange = todo =&gt; {</span>\n<span class=\"grvsc-line\">    dispatch({</span>\n<span class=\"grvsc-line\">      type: todo.complete ? &quot;REMOVE_TODO&quot; : &quot;ADD_TODO&quot;,</span>\n<span class=\"grvsc-line\">      id: todo.id</span>\n<span class=\"grvsc-line\">    });</span>\n<span class=\"grvsc-line\">  };</span>\n<span class=\"grvsc-line\">  return (</span>\n<span class=\"grvsc-line\">    &lt;ul&gt;</span>\n<span class=\"grvsc-line\">      {todos.map(todo =&gt; (</span>\n<span class=\"grvsc-line\">        &lt;li key={todo.id}&gt;</span>\n<span class=\"grvsc-line\">          &lt;label&gt;</span>\n<span class=\"grvsc-line\">            &lt;input</span>\n<span class=\"grvsc-line\">              type=&quot;checkbox&quot;</span>\n<span class=\"grvsc-line\">              checked={todo.complete}</span>\n<span class=\"grvsc-line\">              onChange={() =&gt; handleChange(todo)}</span>\n<span class=\"grvsc-line\">            /&gt;</span>\n<span class=\"grvsc-line\">            {todo.task}</span>\n<span class=\"grvsc-line\">          &lt;/label&gt;</span>\n<span class=\"grvsc-line\">        &lt;/li&gt;</span>\n<span class=\"grvsc-line\">      ))}</span>\n<span class=\"grvsc-line\">    &lt;/ul&gt;</span>\n<span class=\"grvsc-line\">  );</span>\n<span class=\"grvsc-line\">};</span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\">export default App;</span></code></pre>\n<p>Let’s do a similar example with Redux.</p>\n<p>Store in <em>App.js</em>.</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"11\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">import React from &quot;react&quot;;</span>\n<span class=\"grvsc-line\">import { Provider } from &quot;react-redux&quot;;</span>\n<span class=\"grvsc-line\">import { createStore } from &quot;redux&quot;;</span>\n<span class=\"grvsc-line\">import rootReducer from &quot;./reducers&quot;;</span>\n<span class=\"grvsc-line\">import Todo from &quot;./Components/TODO&quot;;</span>\n<span class=\"grvsc-line\">const store = createStore(rootReducer);</span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\">function App() {</span>\n<span class=\"grvsc-line\">  return (</span>\n<span class=\"grvsc-line\">    &lt;div className=&quot;App&quot;&gt;</span>\n<span class=\"grvsc-line\">      &lt;Provider store={store}&gt;</span>\n<span class=\"grvsc-line\">        &lt;Todo /&gt;</span>\n<span class=\"grvsc-line\">      &lt;/Provider&gt;</span>\n<span class=\"grvsc-line\">    &lt;/div&gt;</span>\n<span class=\"grvsc-line\">  );</span>\n<span class=\"grvsc-line\">}</span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\">export default App;</span></code></pre>\n<p>Actions in <em>actions/index.js</em>.</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"12\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">export const addTodo = id =&gt; ({</span>\n<span class=\"grvsc-line\">  type: &quot;ADD_TODO&quot;,</span>\n<span class=\"grvsc-line\">  id</span>\n<span class=\"grvsc-line\">});</span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\">export const removeTodo = id =&gt; ({</span>\n<span class=\"grvsc-line\">  type: &quot;REMOVE_TODO&quot;,</span>\n<span class=\"grvsc-line\">  id</span>\n<span class=\"grvsc-line\">});</span></code></pre>\n<p>Reducers in <em>reducers/index.js</em>.</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"13\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">const initialTodos = [</span>\n<span class=\"grvsc-line\">  {</span>\n<span class=\"grvsc-line\">    id: &quot;t1&quot;,</span>\n<span class=\"grvsc-line\">    task: &quot;Add Task 1&quot;,</span>\n<span class=\"grvsc-line\">    complete: false</span>\n<span class=\"grvsc-line\">  },</span>\n<span class=\"grvsc-line\">  {</span>\n<span class=\"grvsc-line\">    id: &quot;t2&quot;,</span>\n<span class=\"grvsc-line\">    task: &quot;Add Task 2&quot;,</span>\n<span class=\"grvsc-line\">    complete: false</span>\n<span class=\"grvsc-line\">  }</span>\n<span class=\"grvsc-line\">];</span>\n<span class=\"grvsc-line\">const todos = (state = initialTodos, action) =&gt; {</span>\n<span class=\"grvsc-line\">  switch (action.type) {</span>\n<span class=\"grvsc-line\">    case &quot;ADD_TODO&quot;:</span>\n<span class=\"grvsc-line\">      return state.map(todo =&gt; {</span>\n<span class=\"grvsc-line\">        if (todo.id === action.id) {</span>\n<span class=\"grvsc-line\">          return { ...todo, complete: true };</span>\n<span class=\"grvsc-line\">        } else {</span>\n<span class=\"grvsc-line\">          return todo;</span>\n<span class=\"grvsc-line\">        }</span>\n<span class=\"grvsc-line\">      });</span>\n<span class=\"grvsc-line\">    case &quot;REMOVE_TODO&quot;:</span>\n<span class=\"grvsc-line\">      return state.map(todo =&gt; {</span>\n<span class=\"grvsc-line\">        if (todo.id === action.id) {</span>\n<span class=\"grvsc-line\">          return { ...todo, complete: false };</span>\n<span class=\"grvsc-line\">        } else {</span>\n<span class=\"grvsc-line\">          return todo;</span>\n<span class=\"grvsc-line\">        }</span>\n<span class=\"grvsc-line\">      });</span>\n<span class=\"grvsc-line\">    default:</span>\n<span class=\"grvsc-line\">      return state;</span>\n<span class=\"grvsc-line\">  }</span>\n<span class=\"grvsc-line\">};</span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\">export default todos;</span></code></pre>\n<p>FIle components/Todo.js</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"14\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">import React from &quot;react&quot;;</span>\n<span class=\"grvsc-line\">import { connect } from &quot;react-redux&quot;;</span>\n<span class=\"grvsc-line\">import { addTodo, removeTodo } from &quot;../../redux/actions/authActions&quot;;</span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\">const Todo = ({ todos, addTodo, removeTodo }) =&gt; {</span>\n<span class=\"grvsc-line\">  const handleChange = todo =&gt; {</span>\n<span class=\"grvsc-line\">    if (todo.complete) {</span>\n<span class=\"grvsc-line\">      removeTodo(todo.id);</span>\n<span class=\"grvsc-line\">    } else {</span>\n<span class=\"grvsc-line\">      addTodo(todo.id);</span>\n<span class=\"grvsc-line\">    }</span>\n<span class=\"grvsc-line\">  };</span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\">  return (</span>\n<span class=\"grvsc-line\">    &lt;ul&gt;</span>\n<span class=\"grvsc-line\">      {todos.map(todo =&gt; (</span>\n<span class=\"grvsc-line\">        &lt;li key={todo.id}&gt;</span>\n<span class=\"grvsc-line\">          &lt;label&gt;</span>\n<span class=\"grvsc-line\">            &lt;input</span>\n<span class=\"grvsc-line\">              type=&quot;checkbox&quot;</span>\n<span class=\"grvsc-line\">              checked={todo.complete}</span>\n<span class=\"grvsc-line\">              onChange={() =&gt; handleChange(todo)}</span>\n<span class=\"grvsc-line\">            /&gt;</span>\n<span class=\"grvsc-line\">            {todo.task}</span>\n<span class=\"grvsc-line\">          &lt;/label&gt;</span>\n<span class=\"grvsc-line\">        &lt;/li&gt;</span>\n<span class=\"grvsc-line\">      ))}</span>\n<span class=\"grvsc-line\">    &lt;/ul&gt;</span>\n<span class=\"grvsc-line\">  );</span>\n<span class=\"grvsc-line\">};</span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\">const mapStateToProps = state =&gt; ({ todos: state.auth.todos });</span>\n<span class=\"grvsc-line\">const mapDispatchToProps = dispatch =&gt; {</span>\n<span class=\"grvsc-line\">  return {</span>\n<span class=\"grvsc-line\">    addTodo: id =&gt; dispatch(addTodo(id)),</span>\n<span class=\"grvsc-line\">    removeTodo: id =&gt; dispatch(removeTodo(id))</span>\n<span class=\"grvsc-line\">  };</span>\n<span class=\"grvsc-line\">};</span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\">export default connect(</span>\n<span class=\"grvsc-line\">  mapStateToProps,</span>\n<span class=\"grvsc-line\">  mapDispatchToProps</span>\n<span class=\"grvsc-line\">)(Todo);</span></code></pre>\n<p>React offers react hooks which can be used as an alternative for <code>connect()</code>. You can use built-in hooks mainly useState, UseReducer and useContext and because of these you often may not require Redux. </p>\n<p>But for large applications, you can use both redux and react hooks. it works great! React Hook is a useful new feature, and the addition of React-Redux with Redux-specific hooks is a great step towards simplifying Redux development.</p>\n<style class=\"grvsc-styles\">\n  .grvsc-container {\n    overflow: auto;\n    -webkit-overflow-scrolling: touch;\n    padding-top: 1rem;\n    padding-top: var(--grvsc-padding-top, var(--grvsc-padding-v, 1rem));\n    padding-bottom: 1rem;\n    padding-bottom: var(--grvsc-padding-bottom, var(--grvsc-padding-v, 1rem));\n    border-radius: 8px;\n    border-radius: var(--grvsc-border-radius, 8px);\n    font-feature-settings: normal;\n  }\n  \n  .grvsc-code {\n    display: inline-block;\n    min-width: 100%;\n  }\n  \n  .grvsc-line {\n    display: inline-block;\n    box-sizing: border-box;\n    width: 100%;\n    padding-left: 1.5rem;\n    padding-left: var(--grvsc-padding-left, var(--grvsc-padding-h, 1.5rem));\n    padding-right: 1.5rem;\n    padding-right: var(--grvsc-padding-right, var(--grvsc-padding-h, 1.5rem));\n  }\n  \n  .grvsc-line-highlighted {\n    background-color: var(--grvsc-line-highlighted-background-color, transparent);\n    box-shadow: inset var(--grvsc-line-highlighted-border-width, 4px) 0 0 0 var(--grvsc-line-highlighted-border-color, transparent);\n  }\n  \n  .dark-default-dark {\n    background-color: #1E1E1E;\n    color: #D4D4D4;\n  }\n</style>","frontmatter":{"date":"July 17, 2020","updated_date":null,"description":"Learn about React state management and why we need state management and how to use it with React hooks and Redux in the best possible way.","title":"React state management: What is it and why to use it?","tags":["React","Redux","Hooks"],"pinned":null,"coverImage":{"childImageSharp":{"fluid":{"aspectRatio":1.5037593984962405,"src":"/static/ebbce990879fea50a2a8cce920c82894/a3e81/title-image.webp","srcSet":"/static/ebbce990879fea50a2a8cce920c82894/61e93/title-image.webp 200w,\n/static/ebbce990879fea50a2a8cce920c82894/1f5c5/title-image.webp 400w,\n/static/ebbce990879fea50a2a8cce920c82894/a3e81/title-image.webp 512w","sizes":"(max-width: 512px) 100vw, 512px"}}},"author":{"id":"Versha Gupta","github":"vershagupta","avatar":null}}}}]},"markdownRemark":{"excerpt":"Introduction Ever wondered how apps like Spotify, Netflix, or Slack manage seamless login experiences across devices? Many of them use JWT…","fields":{"slug":"/engineering/how-to-integrate-jwt/"},"html":"<h2 id=\"introduction\" style=\"position:relative;\"><a href=\"#introduction\" aria-label=\"introduction permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Introduction</h2>\n<p>Ever wondered how apps like Spotify, Netflix, or Slack manage seamless login experiences across devices? Many of them use JWT, or JSON Web Tokens, a compact, stateless method for securely transmitting user identity and session data across services.</p>\n<p>With JWT token authentication, identity information is embedded in a signed token, allowing you to maintain user sessions without server-side storage. This approach is highly scalable and ideal for modern architectures like SPAs, mobile apps, and microservices.</p>\n<p>In this blog, we’ll walk you through what is JWT, why use it, and how to implement JWT authentication using LoginRadius. </p>\n<p>You’ll learn what JWT is, why it’s effective, and how it works in real-world applications. We'll cover both integration methods (IDX and Direct API), generating your signing key, managing sessions, storing the JWT token securely, and applying best practices throughout.</p>\n<p>Whether you're a developer, product manager, or IAM architect, this guide offers a complete foundation for implementing JWT token authentication into your application stack.</p>\n<h2 id=\"what-is-jwt\" style=\"position:relative;\"><a href=\"#what-is-jwt\" aria-label=\"what is jwt permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>What is JWT?</h2>\n<p><a href=\"https://www.loginradius.com/blog/engineering/jwt/\">JSON Web Token (JWT)</a> is an open standard (RFC 7519) used to transmit information securely between parties as a JSON object. It’s compact, self-contained, and digitally signed, making it a reliable format for authentication and authorization across modern applications.</p>\n<p>A JWT consists of three parts:</p>\n<ol>\n<li><strong>Header –</strong> Contains metadata like the type of token and signing algorithm (e.g., HS256).</li>\n<li><strong>Payload –</strong> Stores the actual data or “claims,” such as user ID, roles, and token expiry.</li>\n<li><strong>Signature –</strong> A cryptographic hash that ensures the token hasn’t been tampered with.</li>\n</ol>\n<p><em>Example of a token structure:</em></p>\n<p>&#x3C;base64Header>.&#x3C;base64Payload>.&#x3C;signature></p>\n<h2 id=\"why-use-jwt\" style=\"position:relative;\"><a href=\"#why-use-jwt\" aria-label=\"why use jwt permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Why Use JWT?</h2>\n<ul>\n<li><strong>Stateless Authentication</strong>: No server-side session storage is needed — the token holds all necessary user info. </li>\n<li><strong>Portable</strong>: Works seamlessly across domains, services, and APIs. </li>\n<li><strong>Scalable</strong>: Ideal for microservices, SPAs, mobile apps, and serverless functions. </li>\n<li><strong>Interoperable</strong>: JWTs are supported across many languages and frameworks.</li>\n</ul>\n<h2 id=\"how-jwt-works\" style=\"position:relative;\"><a href=\"#how-jwt-works\" aria-label=\"how jwt works permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>How JWT Works?</h2>\n<p><img src=\"/f29edbf2978577390c7ffa02e9bc4dda/lr-JWT-authentication.webp\" alt=\"Flowchart illustrating LoginRadius JWT authentication via Identity Provider (IDP), showing user redirection from login icon to login page, authentication with IDP, JWT token validation, and subsequent redirection to the customer&#x27;s website or error page based on validation results.\"></p>\n<ol>\n<li>A user logs in with credentials. </li>\n<li>Your app (or identity provider like LoginRadius) issues a signed JWT. </li>\n<li>The client stores the token and sends it with each request (usually in the Authorization header). </li>\n<li>The server validates the token’s signature and claims. </li>\n<li>If valid, access is granted — without any session stored on the backend.</li>\n</ol>\n<p>JWT simplifies identity verification, especially when you're building apps that talk to APIs or need to scale without centralized session storage.</p>\n<h2 id=\"jwt-authentication-with-loginradius-overview\" style=\"position:relative;\"><a href=\"#jwt-authentication-with-loginradius-overview\" aria-label=\"jwt authentication with loginradius overview permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>JWT Authentication with LoginRadius: Overview</h2>\n<p>LoginRadius provides robust support for JWT (JSON Web Token) authentication, which allows for flexible and secure access control across different digital platforms. Whether you're building a fully custom identity flow or using a pre-built interface, the platform supports various integration approaches depending on your architecture.</p>\n<p>If you're looking to understand how to implement JWT token authentication effectively, LoginRadius offers two primary implementation models that cater to different levels of customization and control:</p>\n<h3 id=\"1-idx-implementation--jwt-through-a-hosted-login-page\" style=\"position:relative;\"><a href=\"#1-idx-implementation--jwt-through-a-hosted-login-page\" aria-label=\"1 idx implementation  jwt through a hosted login page permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>1. IDX Implementation – JWT through a Hosted Login Page</h3>\n<p>The IDX-hosted login approach enables secure, standards-compliant, JWT-based authentication without requiring you to build a custom login interface. This is a strategic option for fast, compliant, and user-friendly deployments.</p>\n<ul>\n<li>The Identity Experience Framework (IDX) comes with a fully custom branded hosted login page.</li>\n<li>Once the user logs in and gets enrolled, the user’s JWTs are automatically generated and issued. These tokens can be utilized for managing user sessions and accessing the APIs.</li>\n<li>This approach simplifies deployment without compromising on user experience and security standards.</li>\n</ul>\n<h3 id=\"configuration-steps\" style=\"position:relative;\"><a href=\"#configuration-steps\" aria-label=\"configuration steps permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a><strong>Configuration Steps:</strong></h3>\n<ol>\n<li>Enable JWT Login</li>\n<li>Go to <a href=\"https://console.loginradius.com/authentication/authentication-configuration\">authentication configuration settings</a> and enable JWT Login in the Admin Console.</li>\n</ol>\n<p><img src=\"/9fb19dd9c88c7916aeebd03ab6e661b7/lr-admin-console.webp\" alt=\"Screenshot of LoginRadius Admin Console showing JWT Custom IDP configuration interface with options for provider name, algorithm (HS256), key entry, clock skew, and expiration time settings.\"></p>\n<ol start=\"2\">\n<li>Specify your signing algorithm and expiry policy, and define your JWT Secret Key.</li>\n<li>Input a secure JWT signing key.</li>\n<li>Specify token expiry duration (e.g., 15–60 minutes)</li>\n<li>Select the desired algorithm —HS256 for symmetric signing (same key signs and verifies)</li>\n<li>RS256 for asymmetric signing, where LoginRadius securely stores the private key used to sign the JWT.</li>\n<li>Your app or backend service uses the public key to validate the token signature.</li>\n<li>LoginRadius provides a JWKS (JSON Web Key Set) endpoint to dynamically fetch and rotate public keys, ensuring trust without key exposure.</li>\n<li>Update IDX Template for Callback</li>\n<li>Modify your IDX login page template to retrieve the JWT post-login. You can access the token via redirect URL parameters or secure JavaScript callbacks.</li>\n</ol>\n<h3 id=\"example-response\" style=\"position:relative;\"><a href=\"#example-response\" aria-label=\"example response permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Example Response:</h3>\n<p>{</p>\n<p>  \"access_token\": \"eyJhbGciOiJIUzI1NiIsInR...\",</p>\n<p>  \"expires_in\": 1800</p>\n<p>}</p>\n<p>This integration approach works best for all teams that want effective identity workflows without the complexity of building proprietary login screens, something that is crucial for customer portals, onboarding of mobile applications, and even managing access for business partners.</p>\n<h3 id=\"2-direct-api-implementation--self-managed-login\" style=\"position:relative;\"><a href=\"#2-direct-api-implementation--self-managed-login\" aria-label=\"2 direct api implementation  self managed login permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>2. Direct API Implementation – Self Managed Login</h3>\n<p>If you’re building a custom login UI or working in a headless environment, LoginRadius lets you generate and handle JWTs directly through its <a href=\"https://www.loginradius.com/docs/api/v2/customer-identity-api/\">Authentication APIs</a>. Here’s how you can programmatically perform token authentication using the classic method:</p>\n<ul>\n<li>For custom front-end applications, LR offers an API to authenticate users and issue JWT tokens.</li>\n<li>In response to the login request, the developers are provided with signed tokens that can be validated on the client’s side or by downstream services.</li>\n<li>This method is best fit for enterprise applications that have complex custom workflows or are designed to be embedded into other applications.</li>\n</ul>\n<h3 id=\"configuration-steps-1\" style=\"position:relative;\"><a href=\"#configuration-steps-1\" aria-label=\"configuration steps 1 permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a><strong>Configuration Steps:</strong></h3>\n<h4 id=\"step-1-authenticate-via-api\" style=\"position:relative;\"><a href=\"#step-1-authenticate-via-api\" aria-label=\"step 1 authenticate via api permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Step 1: Authenticate via API:</h4>\n<ul>\n<li>\n<p>Send a POST login request to the LR Authentication URL: </p>\n<p>POST /identity/v2/auth/login</p>\n</li>\n</ul>\n<p>Include the user’s credentials (email + password) in the request body.</p>\n<h4 id=\"step-2-get-jwt-in-response\" style=\"position:relative;\"><a href=\"#step-2-get-jwt-in-response\" aria-label=\"step 2 get jwt in response permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Step 2: Get JWT in Response</h4>\n<ul>\n<li>If the user credentials are authentic, then the JWT token will be available in response.</li>\n</ul>\n<p>{</p>\n<p> \"access_token\": \"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...\",</p>\n<p> \"expires_in\": 3600</p>\n<p>}</p>\n<h4 id=\"step-3-jwt-decoding-and-validation\" style=\"position:relative;\"><a href=\"#step-3-jwt-decoding-and-validation\" aria-label=\"step 3 jwt decoding and validation permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Step 3: JWT Decoding and Validation</h4>\n<ul>\n<li>Use any JWT library (e.g., jsonwebtoken for Node.js or pyjwt for Python) to decode the token.</li>\n<li>Validate the signature using your configured secret key.</li>\n<li>Confirm claims like exp, iat, aud, and iss.</li>\n</ul>\n<h4 id=\"step-4-set-custom-claims-optional\" style=\"position:relative;\"><a href=\"#step-4-set-custom-claims-optional\" aria-label=\"step 4 set custom claims optional permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Step 4: Set Custom Claims (Optional)</h4>\n<p>With LoginRadius, it is possible to customize the payload to include user roles and/or any additional metadata. You can set custom JWT claims on the Admin Console.</p>\n<p>With this method, you have complete customization over login flows while using LoginRadius to issue signed JWTs for user session management.</p>\n<p><strong>NOTE-</strong> With either method, LoginRadius ensures that JWTs are securely signed, optionally short-lived, and compatible with standard token validation libraries, making integration seamless for everyone.</p>\n<p>To get started with JWT implementation, you can<a href=\"https://www.loginradius.com/docs/single-sign-on/federated-sso/jwt-login/jwt-implementation-guide/\"> read our complete developer documentation</a>. </p>\n<h2 id=\"hosted-login-vs-direct-api\" style=\"position:relative;\"><a href=\"#hosted-login-vs-direct-api\" aria-label=\"hosted login vs direct api permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Hosted Login vs Direct API</h2>\n<p><img src=\"/15ec02ac98d24a9f1f28e5d0f06b9174/IDX-vs-Direct-API-JWT.webp\" alt=\"Illustration showing IDX vs Direct API JWT flow diagram comparing LoginRadius JWT authentication methods via Hosted Login Page (IDX) and Custom Login UI using Direct API, illustrating user login, JWT issuance, and token return process.\"></p>\n<h2 id=\"what-is-session-management-and-how-it-works-with-jwt\" style=\"position:relative;\"><a href=\"#what-is-session-management-and-how-it-works-with-jwt\" aria-label=\"what is session management and how it works with jwt permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>What is Session Management and How It Works with JWT</h2>\n<p><a href=\"https://www.loginradius.com/blog/identity/user-session-management/\">Session management </a>is how your app keeps track of a user after they log in so they don’t have to prove who they are with every request.</p>\n<p>In traditional apps, sessions are stored on the server using session IDs. Every time a request comes in, the server checks that session ID to verify the user.</p>\n<p>In modern apps, especially SPAs and APIs, JWTs are used to manage sessions without needing server-side storage; this is called stateless session management. The token itself carries the user’s identity, roles, and expiration details. As long as the token is valid, the user stays logged in.</p>\n<p>Good session management ensures:</p>\n<ul>\n<li>Security against session hijacking</li>\n<li>Fast user validation without hitting a database</li>\n<li>Smooth experiences with token refresh strategies</li>\n</ul>\n<h2 id=\"how-loginradius-handles-session-management-with-jwt\" style=\"position:relative;\"><a href=\"#how-loginradius-handles-session-management-with-jwt\" aria-label=\"how loginradius handles session management with jwt permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>How LoginRadius Handles Session Management with JWT:</h2>\n<ol>\n<li>\n<p>User Logs In </p>\n<ul>\n<li>LoginRadius returns an access token (JWT) and, optionally, a refresh token.</li>\n</ul>\n</li>\n<li>\n<p>Client Stores the Token </p>\n<ul>\n<li>Access tokens are stored in memory, sessionStorage, or secure cookies. </li>\n<li>They’re sent on every request via the Authorization: Bearer header. </li>\n</ul>\n</li>\n<li>\n<p>Access Token Expiry </p>\n<ul>\n<li>These tokens are short-lived by design (e.g., 15–30 minutes). </li>\n<li>Once expired, the client can use the refresh token to request a new access token. </li>\n</ul>\n</li>\n<li>\n<p>Token Renewal </p>\n<ul>\n<li>LoginRadius validates the refresh token and issues a new JWT, i.e., no user re-authentication is needed. </li>\n<li>Refresh tokens can be revoked at any time.</li>\n</ul>\n</li>\n<li>Logout and Token Revocation Strategy</li>\n</ol>\n<p>When the user logs out, both the access token and refresh token should be cleared from client storage.</p>\n<ul>\n<li>The refresh token can be explicitly revoked via the LoginRadius API, terminating the ability to renew sessions. </li>\n<li>\n<p>However, access tokens are stateless and cannot be revoked mid-lifecycle unless: </p>\n<ul>\n<li>You maintain a blacklist of token IDs (jti claims) and check them on each request. </li>\n<li>You use short-lived access tokens to limit exposure naturally. </li>\n<li>Or, you rotate your JWT signing key, invalidating all previously issued tokens. </li>\n</ul>\n</li>\n</ul>\n<p>Combining these strategies gives you greater control over token misuse and enables a robust, enterprise-grade logout flow. </p>\n<p><a href=\"https://www.loginradius.com/resource/whitepaper/secure-api-using-oauth2\"><img src=\"/e55ae4bbc8ce62e13f03e46e29ebe7cc/api-economy.webp\" alt=\"illustration showing LoginRadius free downloadable resource named API economy is transforming digitization: how to secure it using oauth 2.0.\"></a></p>\n<h2 id=\"how-to-store-jwt-tokens\" style=\"position:relative;\"><a href=\"#how-to-store-jwt-tokens\" aria-label=\"how to store jwt tokens permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>How to Store JWT Tokens?</h2>\n<p>When you implement JWT-based authentication, the client (browser or mobile app) needs a way to store the access token and, optionally, the refresh token after they are issued by the authentication server. This stored token is then attached to every subsequent request to prove the user's identity.</p>\n<p>Choosing where to store the JWT is a crucial security decision. The most common storage options are:</p>\n<ul>\n<li>localStorage</li>\n<li>sessionStorage</li>\n<li>HTTP-only cookies</li>\n</ul>\n<p>Each option has trade-offs between security, accessibility, and persistence, and the right choice depends on your application's architecture and threat model.</p>\n<h4 id=\"recommended-storage-strategy\" style=\"position:relative;\"><a href=\"#recommended-storage-strategy\" aria-label=\"recommended storage strategy permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Recommended Storage Strategy</h4>\n<ul>\n<li>\n<p>Access Tokens </p>\n<ul>\n<li>For SPAs: store in memory or sessionStorage for short-term access </li>\n<li>If stored in the browser, protect against XSS </li>\n</ul>\n</li>\n<li>\n<p>Refresh Tokens</p>\n<ul>\n<li>Always store the JWT refresh token in HTTP-only secure cookies to prevent JavaScript access. This adds a critical layer of protection against XSS attacks.</li>\n<li>Combine with SameSite=Strict or SameSite=Lax attributes to mitigate CSRF risks and ensure the JWT refresh token is only sent in intended contexts.</li>\n</ul>\n</li>\n</ul>\n<h2 id=\"best-practices-for-storing-jwts\" style=\"position:relative;\"><a href=\"#best-practices-for-storing-jwts\" aria-label=\"best practices for storing jwts permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Best Practices for Storing JWTs</h2>\n<ol>\n<li>Never store sensitive tokens (like refresh tokens) in localStorage or sessionStorage.</li>\n<li>Use Secure and HttpOnly flags with cookies to prevent JavaScript access and ensure transmission only over HTTPS.</li>\n<li>Set the SameSite=Strict or Lax attribute on cookies to protect against CSRF.</li>\n<li>Use short-lived access tokens and rotate refresh tokens regularly.</li>\n<li>Implement CSP (Content Security Policy) to reduce XSS risk.</li>\n<li>Avoid storing any tokens in frontend code (e.g., hardcoded in JS files).</li>\n</ol>\n<h2 id=\"conclusion\" style=\"position:relative;\"><a href=\"#conclusion\" aria-label=\"conclusion permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Conclusion</h2>\n<p>JWT authentication with LoginRadius offers a modern, stateless approach to managing sessions across distributed systems. The IDX integration is ideal for rapid deployment, while the Direct API model is best for organizations needing deep customization and integration flexibility.</p>\n<p>With robust token signing, refresh capabilities, and centralized control, LoginRadius provides a future-ready foundation for secure, scalable identity architecture. <a href=\"https://www.loginradius.com/contact-us?utm_source=blog&#x26;utm_medium=web&#x26;utm_campaign=how-to-integrate-jwt\">Contact us</a> to know more about JWT authentication and implementation guide. </p>\n<h2 id=\"faqs\" style=\"position:relative;\"><a href=\"#faqs\" aria-label=\"faqs permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>FAQs</h2>\n<h3 id=\"1-what-is-jwt-authentication-used-for\" style=\"position:relative;\"><a href=\"#1-what-is-jwt-authentication-used-for\" aria-label=\"1 what is jwt authentication used for permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>1. What is JWT authentication used for?</h3>\n<p><strong>A:</strong> JWT authentication securely verifies user identities, enabling stateless session management across web, mobile apps, and microservices without server-side session storage.</p>\n<h3 id=\"2-how-does-loginradius-simplify-jwt-integration\" style=\"position:relative;\"><a href=\"#2-how-does-loginradius-simplify-jwt-integration\" aria-label=\"2 how does loginradius simplify jwt integration permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>2. How does LoginRadius simplify JWT integration?</h3>\n<p><strong>A:</strong> LoginRadius simplifies JWT integration by offering hosted <a href=\"https://www.loginradius.com/docs/single-sign-on/federated-sso/jwt-login/jwt-implementation-guide/\">IDX login pages </a>and direct API-based authentication methods, enabling rapid deployment and deep customization.</p>\n<h3 id=\"3-is-jwt-authentication-secure\" style=\"position:relative;\"><a href=\"#3-is-jwt-authentication-secure\" aria-label=\"3 is jwt authentication secure permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>3. Is JWT authentication secure?</h3>\n<p><strong>A:</strong> Yes, JWT authentication is secure when implemented with best practices like short-lived tokens, secure storage methods, signature validation, and refresh token rotation.</p>\n<h3 id=\"4-can-jwt-tokens-be-revoked-with-loginradius\" style=\"position:relative;\"><a href=\"#4-can-jwt-tokens-be-revoked-with-loginradius\" aria-label=\"4 can jwt tokens be revoked with loginradius permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>4. Can JWT tokens be revoked with LoginRadius?</h3>\n<p><strong>A:</strong> Yes, LoginRadius allows<a href=\"https://www.loginradius.com/docs/api/v2/customer-identity-api/refresh-token/revoke-refresh-token/?q=revoke+jwt\"> revocation of JWT</a> refresh tokens explicitly, and supports strategies like short-lived tokens and key rotation to manage token lifecycles securely.</p>\n<style class=\"grvsc-styles\">\n  .grvsc-container {\n    overflow: auto;\n    -webkit-overflow-scrolling: touch;\n    padding-top: 1rem;\n    padding-top: var(--grvsc-padding-top, var(--grvsc-padding-v, 1rem));\n    padding-bottom: 1rem;\n    padding-bottom: var(--grvsc-padding-bottom, var(--grvsc-padding-v, 1rem));\n    border-radius: 8px;\n    border-radius: var(--grvsc-border-radius, 8px);\n    font-feature-settings: normal;\n  }\n  \n  .grvsc-code {\n    display: inline-block;\n    min-width: 100%;\n  }\n  \n  .grvsc-line {\n    display: inline-block;\n    box-sizing: border-box;\n    width: 100%;\n    padding-left: 1.5rem;\n    padding-left: var(--grvsc-padding-left, var(--grvsc-padding-h, 1.5rem));\n    padding-right: 1.5rem;\n    padding-right: var(--grvsc-padding-right, var(--grvsc-padding-h, 1.5rem));\n  }\n  \n  .grvsc-line-highlighted {\n    background-color: var(--grvsc-line-highlighted-background-color, transparent);\n    box-shadow: inset var(--grvsc-line-highlighted-border-width, 4px) 0 0 0 var(--grvsc-line-highlighted-border-color, transparent);\n  }\n  \n</style>","frontmatter":{"date":"April 15, 2025","updated_date":null,"description":"Discover JWT (JSON Web Token) authentication, its advantages, and how to integrate it seamlessly using LoginRadius' hosted IDX and Direct API methods for secure, scalable identity management.","title":"JWT Authentication with LoginRadius: Quick Integration Guide","tags":["JWT","JSON Web Token","Authentication","Authorization"],"pinned":null,"coverImage":{"childImageSharp":{"fluid":{"aspectRatio":0.7782101167315175,"src":"/static/4cedb7829f98208cbc6d5a9aea4e983d/58556/how-to-integrate-jwt.webp","srcSet":"/static/4cedb7829f98208cbc6d5a9aea4e983d/61e93/how-to-integrate-jwt.webp 200w,\n/static/4cedb7829f98208cbc6d5a9aea4e983d/1f5c5/how-to-integrate-jwt.webp 400w,\n/static/4cedb7829f98208cbc6d5a9aea4e983d/58556/how-to-integrate-jwt.webp 800w,\n/static/4cedb7829f98208cbc6d5a9aea4e983d/1cc9f/how-to-integrate-jwt.webp 896w","sizes":"(max-width: 800px) 100vw, 800px"}}},"author":{"id":"Kundan Singh","github":null,"avatar":null}}}},"pageContext":{"limit":6,"skip":192,"currentPage":33,"type":"//engineering//","numPages":53,"pinned":"5c425581-f474-5ae9-abe7-cf5342db2aaa"}},"staticQueryHashes":["1171199041","1384082988","2100481360","23180105","528864852"]}