{"componentChunkName":"component---src-templates-blog-list-template-js","path":"/engineering/4","result":{"data":{"allMarkdownRemark":{"edges":[{"node":{"excerpt":"In this tutorial, I’ll talk about adding authentication in a Svelte application using LoginRadius Authentication APIs. You'll understand…","fields":{"slug":"/engineering/guest-post/authenticating-svelte-apps/"},"html":"<p>In this tutorial, I’ll talk about adding authentication in a Svelte application using LoginRadius Authentication APIs. You'll understand step by step how to:</p>\n<ul>\n<li>create forms in Svelte;</li>\n<li>add reactivity to it;</li>\n<li>configure routing for our Svelte app; and,</li>\n<li>setup protected routes for authenticated users.</li>\n</ul>\n<p>You'll also learn how to consume REST APIs in a Svelte app using Fetch API and update user information in your Svelte store.</p>\n<h2 id=\"what-is-svelte\" style=\"position:relative;\"><a href=\"#what-is-svelte\" aria-label=\"what is svelte 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 Svelte?</h2>\n<p><a href=\"https://svelte.dev/\">Svelte</a> is a lightweight and minimal JavaScript compiler that ships a single JavaScript bundle to your application without any internal code of its own. This results in smaller bundle size and often a faster running application. It was also the <a href=\"https://insights.stackoverflow.com/survey/2021#section-most-loved-dreaded-and-wanted-web-frameworks\">most loved framework of 2021</a>.</p>\n<p>But what's the first feature you'd add in a Svelte application? Authentication! It's the gateway for your users to interact and use your website.</p>\n<p>So in this post, I’ll talk about how to add authentication in a Svelte application.</p>\n<h2 id=\"svelte-project-demo\" style=\"position:relative;\"><a href=\"#svelte-project-demo\" aria-label=\"svelte project demo 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>Svelte Project Demo</h2>\n<p>You'll learn how to create forms in Svelte and add reactivity to it. You'll also understand how to conditionally render different UI components and set up protected routes for authenticated users in a Svelte application.</p>\n<p>To speed things up, you won't build your own authentication services from scratch. Instead, you'll use <a href=\"https://accounts.loginradius.com/auth.aspx?plan=developer&#x26;action=register\">LoginRadius</a> to quickly configure an authentication backend for your Svelte App.</p>\n<p>Here's a little demo of what your Svelte App would look like by the end of the tutorial:</p>\n<p><video controls width=\"700\" align=\"center\" src=\"/648a1d1a74555638a162015f5d7769b5/Svelte-Auth-LoginRadius-Demo.mp4\"/> </video></p>\n<p>Looks exciting? Let's jump right into it!</p>\n<h2 id=\"setup-a-svelte-app\" style=\"position:relative;\"><a href=\"#setup-a-svelte-app\" aria-label=\"setup a svelte app 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>Setup a Svelte App</h2>\n<p>Let's start by creating a new Svelte project and adding some boilerplate code.</p>\n<h3 id=\"create-a-new-svelte-project\" style=\"position:relative;\"><a href=\"#create-a-new-svelte-project\" aria-label=\"create a new svelte 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>Create a New Svelte Project</h3>\n<p>Navigate into the directory of your choice and create a new Svelte project by running:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"0\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">npx degit sveltejs/template svelte-auth-app</span></code></pre>\n<p>That should create a new Svelte project with a simple starter template.</p>\n<p>Additionally, you'll need to install <a href=\"https://github.com/mefechoel/svelte-navigator\">svelte-navigator</a> package to set up routing in your Svelte app:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"1\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">npm i svelte-navigator</span></code></pre>\n<h3 id=\"configure-environment-variable-support\" style=\"position:relative;\"><a href=\"#configure-environment-variable-support\" aria-label=\"configure environment variable support 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>Configure Environment Variable Support</h3>\n<p>You need to add environment variable support in your Svelte app to store and use your LoginRadius API Keys and Secrets.</p>\n<p>First, install a package called <a href=\"https://www.npmjs.com/package/dotenv\">dotenv</a> that let's create and use a special <code>.env</code> file to define your environment variables.</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"2\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">npm i dotenv</span></code></pre>\n<p>Next, head over to the <code>rollup.config.js</code> file. Here, make some configurational changes on the <code>plugins</code> property, so your Svelte app can read those environment variables on the client-side:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"javascript\" data-index=\"3\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk1\">\t...</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">\tplugins: [</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">\t\t</span><span class=\"mtk11\">replace</span><span class=\"mtk1\">({</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">\t\t\t</span><span class=\"mtk3\">// stringify the object</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">\t\t\t</span><span class=\"mtk12\">__myapp:</span><span class=\"mtk1\"> </span><span class=\"mtk10\">JSON</span><span class=\"mtk1\">.</span><span class=\"mtk11\">stringify</span><span class=\"mtk1\">({</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">\t\t\t  </span><span class=\"mtk12\">env:</span><span class=\"mtk1\"> {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">\t\t\t\t</span><span class=\"mtk12\">isProd:</span><span class=\"mtk1\"> </span><span class=\"mtk12\">production</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">\t\t\t\t...</span><span class=\"mtk11\">config</span><span class=\"mtk1\">().</span><span class=\"mtk12\">parsed</span><span class=\"mtk1\"> </span><span class=\"mtk3\">// attached the .env config</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">\t\t\t  }</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">\t\t\t}),</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">\t\t  }),</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    ...</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">\t],</span></span></code></pre>\n<p>You can refer to the complete <code>rollup.config.js</code> file for this project <a href=\"https://github.com/LoginRadius/engineering-blog-samples/blob/master/Svelte/SvelteAuthApp/rollup.config.js\">here</a>.</p>\n<h3 id=\"create-files-and-folders\" style=\"position:relative;\"><a href=\"#create-files-and-folders\" aria-label=\"create files and folders 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>Create Files and Folders</h3>\n<p>Besides the initial set of files, your project will have the following directory structure:</p>\n<p><img src=\"/b127258daa14eecbda3f07a8bccce890/Directory-Structure-Svelte-App.png\" alt=\"Directory Structure Svelte App\"></p>\n<p>So go ahead and create those files and folders accordingly. I'll talk about each of these as you start filling them with some code.</p>\n<h3 id=\"add-project-styles\" style=\"position:relative;\"><a href=\"#add-project-styles\" aria-label=\"add project styles 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>Add Project Styles</h3>\n<p>Your starter template should come with the following styles inside your <code>App.svelte file</code>:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"css\" data-index=\"4\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk6\">main</span><span class=\"mtk1\"> {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  </span><span class=\"mtk12\">text-align</span><span class=\"mtk1\">: </span><span class=\"mtk8\">center</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  </span><span class=\"mtk12\">padding</span><span class=\"mtk1\">: </span><span class=\"mtk7\">1em</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  </span><span class=\"mtk12\">max-width</span><span class=\"mtk1\">: </span><span class=\"mtk7\">240px</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  </span><span class=\"mtk12\">margin</span><span class=\"mtk1\">: </span><span class=\"mtk7\">0</span><span class=\"mtk1\"> </span><span class=\"mtk8\">auto</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=\"mtk6\">h1</span><span class=\"mtk1\"> {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  </span><span class=\"mtk12\">color</span><span class=\"mtk1\">: </span><span class=\"mtk8\">#ff3e00</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  </span><span class=\"mtk12\">text-transform</span><span class=\"mtk1\">: </span><span class=\"mtk8\">uppercase</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  </span><span class=\"mtk12\">font-size</span><span class=\"mtk1\">: </span><span class=\"mtk7\">4em</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  </span><span class=\"mtk12\">font-weight</span><span class=\"mtk1\">: </span><span class=\"mtk7\">100</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=\"mtk15\">@media</span><span class=\"mtk1\"> (</span><span class=\"mtk12\">min-width</span><span class=\"mtk1\">: </span><span class=\"mtk7\">640px</span><span class=\"mtk1\">) {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  </span><span class=\"mtk6\">main</span><span class=\"mtk1\"> {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk12\">max-width</span><span class=\"mtk1\">: </span><span class=\"mtk8\">none</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>However, I have also added some additional styles inside the global stylesheet inside the <code>/public/build/global.css</code> file. You can copy those styles from <a href=\"https://github.com/LoginRadius/engineering-blog-samples/blob/master/Svelte/SvelteAuthApp/public/global.css\">here</a>.</p>\n<h2 id=\"global-data-store-for-authenticated-user\" style=\"position:relative;\"><a href=\"#global-data-store-for-authenticated-user\" aria-label=\"global data store for authenticated user 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>Global Data Store for Authenticated User</h2>\n<p>Your Svelte app will store the authenticated user's data in a global data store to easily access and modify that data from any component within your application. Svelte provides you with the <code>writable</code> function inside the <code>svelte/store</code> dependency.</p>\n<p>Create a global object called <code>user</code> inside your <code>/src/stores.js</code> file:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"javascript\" data-index=\"5\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk15\">import</span><span class=\"mtk1\"> { </span><span class=\"mtk12\">writable</span><span class=\"mtk1\"> } </span><span class=\"mtk15\">from</span><span class=\"mtk1\"> </span><span class=\"mtk8\">&quot;svelte/store&quot;</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk15\">export</span><span class=\"mtk1\"> </span><span class=\"mtk4\">const</span><span class=\"mtk1\"> </span><span class=\"mtk12\">user</span><span class=\"mtk1\"> = </span><span class=\"mtk11\">writable</span><span class=\"mtk1\">(</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  </span><span class=\"mtk12\">localStorage</span><span class=\"mtk1\">.</span><span class=\"mtk12\">user</span><span class=\"mtk1\"> ? </span><span class=\"mtk10\">JSON</span><span class=\"mtk1\">.</span><span class=\"mtk11\">parse</span><span class=\"mtk1\">(</span><span class=\"mtk12\">localStorage</span><span class=\"mtk1\">.</span><span class=\"mtk11\">getItem</span><span class=\"mtk1\">(</span><span class=\"mtk8\">&quot;user&quot;</span><span class=\"mtk1\">)) : </span><span class=\"mtk4\">null</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">)</span></span></code></pre>\n<p>You have also synced the above <code>user</code> object with the browser's local storage so that this data persists on page reloads. If you're unfamiliar with what local storage is, <a href=\"https://www.loginradius.com/blog/engineering/guest-post/local-storage-vs-session-storage-vs-cookies/\">check out my guide on Local Storage vs. Session Storage vs. Cookies</a> that dives deeper into browser storage and other related concepts.</p>\n<h2 id=\"the-app-component-boilerplate\" style=\"position:relative;\"><a href=\"#the-app-component-boilerplate\" aria-label=\"the app component boilerplate 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>The App Component Boilerplate</h2>\n<p>The root component in your Svelte app is the App Component. This is located inside <code>/src/App.svelte</code>.</p>\n<p>It has the following imports declared inside:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"javascript\" data-index=\"6\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk17\">&lt;</span><span class=\"mtk4\">script</span><span class=\"mtk17\">&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  /** IMPORTS */ import Login from &#39;./Login.svelte&#39;; import Signup from</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  &#39;./Signup.svelte&#39;; import Home from &#39;./Home.svelte&#39;; import PrivateRoute from</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  &quot;./routes/PrivateRoutes.svelte&quot;; /** VARIABLES */ const sdkoptions = </span><span class=\"mtk4\">{}</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk17\">&lt;/</span><span class=\"mtk4\">script</span><span class=\"mtk17\">&gt;</span></span></code></pre>\n<p>It also has an <code>sdkoptions</code> variable that will store the environment variables that you can easily pass to different components as and when they need it. You can get rid of any additional HTML inside the <code>App.svelte</code> file generated by the starter template.</p>\n<h2 id=\"the-login-component\" style=\"position:relative;\"><a href=\"#the-login-component\" aria-label=\"the login component 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>The Login Component</h2>\n<p>Let's head over to the <code>/src/Login.svelte</code> file to create the Login Page.</p>\n<h3 id=\"create-login-form\" style=\"position:relative;\"><a href=\"#create-login-form\" aria-label=\"create login form 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>Create Login Form</h3>\n<p>Here's what the HTML of your Login Form consists of:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"html\" data-index=\"7\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk17\">&lt;</span><span class=\"mtk4\">h3</span><span class=\"mtk17\">&gt;</span><span class=\"mtk1\">Login</span><span class=\"mtk17\">&lt;/</span><span class=\"mtk4\">h3</span><span class=\"mtk17\">&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk17\">&lt;</span><span class=\"mtk4\">form</span><span class=\"mtk1\"> </span><span class=\"mtk14\">on:submit|preventDefault=&quot;{handleSubmit}&quot;&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  </span><span class=\"mtk14\">&lt;input</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk12\">class</span><span class=\"mtk1\">=</span><span class=\"mtk8\">&quot;form-field&quot;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk12\">bind</span><span class=\"mtk1\">:</span><span class=\"mtk12\">value</span><span class=\"mtk1\">=</span><span class=\"mtk8\">&quot;{email}&quot;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk12\">type</span><span class=\"mtk1\">=</span><span class=\"mtk8\">&quot;email&quot;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk12\">placeholder</span><span class=\"mtk1\">=</span><span class=\"mtk8\">&quot;Email&quot;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  </span><span class=\"mtk17\">/&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  </span><span class=\"mtk17\">&lt;</span><span class=\"mtk4\">input</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk12\">class</span><span class=\"mtk1\">=</span><span class=\"mtk8\">&quot;form-field&quot;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk12\">bind</span><span class=\"mtk1\">:</span><span class=\"mtk12\">value</span><span class=\"mtk1\">=</span><span class=\"mtk8\">&quot;{password}&quot;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk12\">type</span><span class=\"mtk1\">=</span><span class=\"mtk8\">&quot;password&quot;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk12\">placeholder</span><span class=\"mtk1\">=</span><span class=\"mtk8\">&quot;Password&quot;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  </span><span class=\"mtk17\">/&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  </span><span class=\"mtk17\">&lt;</span><span class=\"mtk4\">button</span><span class=\"mtk1\"> </span><span class=\"mtk12\">class</span><span class=\"mtk1\">=</span><span class=\"mtk8\">&quot;form-field&quot;</span><span class=\"mtk17\">&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    Login</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  </span><span class=\"mtk17\">&lt;/</span><span class=\"mtk4\">button</span><span class=\"mtk17\">&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">&lt;/</span><span class=\"mtk12\">form</span><span class=\"mtk1\">&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk17\">&lt;</span><span class=\"mtk4\">p</span><span class=\"mtk17\">&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  Don&#39;t have an account?</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  </span><span class=\"mtk17\">&lt;</span><span class=\"mtk4\">strong</span><span class=\"mtk1\"> </span><span class=\"mtk12\">class</span><span class=\"mtk1\">=</span><span class=\"mtk8\">&quot;link&quot;</span><span class=\"mtk1\"> </span><span class=\"mtk12\">on</span><span class=\"mtk1\">:</span><span class=\"mtk12\">click</span><span class=\"mtk1\">=</span><span class=\"mtk8\">&quot;{navigateToSignup}&quot;</span><span class=\"mtk17\">&gt;</span><span class=\"mtk1\">Sign up</span><span class=\"mtk17\">&lt;/</span><span class=\"mtk4\">strong</span><span class=\"mtk17\">&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk17\">&lt;/</span><span class=\"mtk4\">p</span><span class=\"mtk17\">&gt;</span></span></code></pre>\n<p>You have a login form with two input fields for email and password and a submit button. The form also has an <code>on:submit</code> handler with an event modifier to prevent the default reloading action of the form when it gets submitted.</p>\n<p>After the form, you have a simple link with an <code>on:click</code> handler that allows the user to navigate to the Signup page.</p>\n<h3 id=\"login-form-field-bindings-and-handlers\" style=\"position:relative;\"><a href=\"#login-form-field-bindings-and-handlers\" aria-label=\"login form field bindings and handlers 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>Login Form Field Bindings and Handlers</h3>\n<p>Inside the script of your Login component, create two variables — <code>email</code> and <code>password</code> — to handle the bindings to the input fields. Also, make the <code>sdkoptions</code> variable exportable since you'll receive it as <code>props</code> from the App component.</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"javascript\" data-index=\"8\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk17\">&lt;</span><span class=\"mtk4\">script</span><span class=\"mtk17\">&gt;</span><span class=\"mtk1\">let email; let password; export let sdkoptions;</span><span class=\"mtk17\">&lt;/</span><span class=\"mtk4\">script</span><span class=\"mtk17\">&gt;</span></span></code></pre>\n<p>You also need to create a function called <code>handleSubmit</code> that is the <code>on:submit</code> handler for your Login form:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"javascript\" data-index=\"9\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk17\">&lt;</span><span class=\"mtk4\">script</span><span class=\"mtk17\">&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">\t...</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    const handleSubmit=(e)=&gt;</span><span class=\"mtk4\">{</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">       </span><span class=\"mtk12\">let</span><span class=\"mtk1\"> </span><span class=\"mtk12\">loginFields</span><span class=\"mtk1\">={</span><span class=\"mtk12\">email</span><span class=\"mtk1\">,</span><span class=\"mtk12\">password</span><span class=\"mtk1\">};</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">\t   </span><span class=\"mtk10\">console</span><span class=\"mtk1\">.</span><span class=\"mtk11\">log</span><span class=\"mtk1\">(</span><span class=\"mtk12\">loginFields</span><span class=\"mtk1\">)</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk4\">}</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    const navigateToSignup=()=&gt;</span><span class=\"mtk4\">{}</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk17\">&lt;/</span><span class=\"mtk4\">script</span><span class=\"mtk17\">&gt;</span></span></code></pre>\n<p>At the moment, you're simply encapsulating the <code>email</code> and <code>password</code> bindings into a JavaScript object. Later, you'll send a request to your Login API here. You also have an empty <code>navigateToSignup</code> function that I'll come back to once you set up your routes.</p>\n<p>Let's render the Login component inside your <code>App.svelte</code> file:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"html\" data-index=\"10\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk17\">&lt;</span><span class=\"mtk4\">main</span><span class=\"mtk17\">&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  </span><span class=\"mtk17\">&lt;</span><span class=\"mtk10\">Login</span><span class=\"mtk1\"> </span><span class=\"mtk17\">/&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk17\">&lt;/</span><span class=\"mtk4\">main</span><span class=\"mtk17\">&gt;</span></span></code></pre>\n<p><img src=\"/a83987b29ea11ed6919d189c638e18b3/Login-Page.png\" alt=\"Login Page\"></p>\n<p>Awesome! Let's follow the same process to create your Signup form.</p>\n<h2 id=\"the-signup-component\" style=\"position:relative;\"><a href=\"#the-signup-component\" aria-label=\"the signup component 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>The Signup Component</h2>\n<p>Head over to the <code>/src/Signup.svelte</code> file to create your Signup Page.</p>\n<h3 id=\"create-signup-form\" style=\"position:relative;\"><a href=\"#create-signup-form\" aria-label=\"create signup form 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>Create Signup Form</h3>\n<p>Similar to the Login Form, the Signup Form will have the following HTML:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"html\" data-index=\"11\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk17\">&lt;</span><span class=\"mtk4\">h3</span><span class=\"mtk17\">&gt;</span><span class=\"mtk1\">Create a New Account</span><span class=\"mtk17\">&lt;/</span><span class=\"mtk4\">h3</span><span class=\"mtk17\">&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk17\">&lt;</span><span class=\"mtk4\">form</span><span class=\"mtk1\"> </span><span class=\"mtk14\">on:submit|preventDefault=&quot;{handleSubmit}&quot;&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  </span><span class=\"mtk14\">&lt;input</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk12\">class</span><span class=\"mtk1\">=</span><span class=\"mtk8\">&quot;form-field&quot;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk12\">bind</span><span class=\"mtk1\">:</span><span class=\"mtk12\">value</span><span class=\"mtk1\">=</span><span class=\"mtk8\">&quot;{firstName}&quot;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk12\">type</span><span class=\"mtk1\">=</span><span class=\"mtk8\">&quot;text&quot;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk12\">placeholder</span><span class=\"mtk1\">=</span><span class=\"mtk8\">&quot;First Name&quot;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  </span><span class=\"mtk17\">/&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  </span><span class=\"mtk17\">&lt;</span><span class=\"mtk4\">input</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk12\">class</span><span class=\"mtk1\">=</span><span class=\"mtk8\">&quot;form-field&quot;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk12\">bind</span><span class=\"mtk1\">:</span><span class=\"mtk12\">value</span><span class=\"mtk1\">=</span><span class=\"mtk8\">&quot;{lastName}&quot;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk12\">type</span><span class=\"mtk1\">=</span><span class=\"mtk8\">&quot;text&quot;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk12\">placeholder</span><span class=\"mtk1\">=</span><span class=\"mtk8\">&quot;Last Name&quot;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  </span><span class=\"mtk17\">/&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  </span><span class=\"mtk17\">&lt;</span><span class=\"mtk4\">input</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk12\">class</span><span class=\"mtk1\">=</span><span class=\"mtk8\">&quot;form-field&quot;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk12\">bind</span><span class=\"mtk1\">:</span><span class=\"mtk12\">value</span><span class=\"mtk1\">=</span><span class=\"mtk8\">&quot;{email}&quot;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk12\">type</span><span class=\"mtk1\">=</span><span class=\"mtk8\">&quot;email&quot;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk12\">placeholder</span><span class=\"mtk1\">=</span><span class=\"mtk8\">&quot;Email&quot;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  </span><span class=\"mtk17\">/&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  </span><span class=\"mtk17\">&lt;</span><span class=\"mtk4\">input</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk12\">class</span><span class=\"mtk1\">=</span><span class=\"mtk8\">&quot;form-field&quot;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk12\">bind</span><span class=\"mtk1\">:</span><span class=\"mtk12\">value</span><span class=\"mtk1\">=</span><span class=\"mtk8\">&quot;{password}&quot;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk12\">type</span><span class=\"mtk1\">=</span><span class=\"mtk8\">&quot;password&quot;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk12\">placeholder</span><span class=\"mtk1\">=</span><span class=\"mtk8\">&quot;Password&quot;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  </span><span class=\"mtk17\">/&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  </span><span class=\"mtk17\">&lt;</span><span class=\"mtk4\">button</span><span class=\"mtk1\"> </span><span class=\"mtk12\">class</span><span class=\"mtk1\">=</span><span class=\"mtk8\">&quot;form-field&quot;</span><span class=\"mtk17\">&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    Signup</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  </span><span class=\"mtk17\">&lt;/</span><span class=\"mtk4\">button</span><span class=\"mtk17\">&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">&lt;/</span><span class=\"mtk12\">form</span><span class=\"mtk1\">&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk17\">&lt;</span><span class=\"mtk4\">p</span><span class=\"mtk17\">&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  Already have an account?</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  </span><span class=\"mtk17\">&lt;</span><span class=\"mtk4\">strong</span><span class=\"mtk1\"> </span><span class=\"mtk12\">class</span><span class=\"mtk1\">=</span><span class=\"mtk8\">&quot;link&quot;</span><span class=\"mtk1\"> </span><span class=\"mtk12\">on</span><span class=\"mtk1\">:</span><span class=\"mtk12\">click</span><span class=\"mtk1\">=</span><span class=\"mtk8\">&quot;{navigateToLogin}&quot;</span><span class=\"mtk17\">&gt;</span><span class=\"mtk1\">Login</span><span class=\"mtk17\">&lt;/</span><span class=\"mtk4\">strong</span><span class=\"mtk17\">&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk17\">&lt;/</span><span class=\"mtk4\">p</span><span class=\"mtk17\">&gt;</span></span></code></pre>\n<p>The only difference is now you have two additional fields — first name and last name. You also have a link just below the signup form that takes the user to the login page.</p>\n<h3 id=\"signup-form-field-bindings-and-handlers\" style=\"position:relative;\"><a href=\"#signup-form-field-bindings-and-handlers\" aria-label=\"signup form field bindings and handlers 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>Signup Form Field Bindings and Handlers</h3>\n<p>Here's what the script section of your <code>Signup.svelte</code> file should look like:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"javascript\" data-index=\"12\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk17\">&lt;</span><span class=\"mtk4\">script</span><span class=\"mtk17\">&gt;</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">\tlet email;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    let password;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    let firstName;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    let lastName;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    let loading;</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    export let sdkoptions;</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    const handleSubmit=()=&gt;</span><span class=\"mtk4\">{</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">        </span><span class=\"mtk12\">const</span><span class=\"mtk1\"> </span><span class=\"mtk12\">signupFields</span><span class=\"mtk1\">={</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">            </span><span class=\"mtk8\">&quot;FirstName&quot;</span><span class=\"mtk12\">:</span><span class=\"mtk1\"> </span><span class=\"mtk12\">firstName</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">            </span><span class=\"mtk8\">&quot;LastName&quot;</span><span class=\"mtk12\">:</span><span class=\"mtk1\"> </span><span class=\"mtk12\">lastName</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">            </span><span class=\"mtk8\">&quot;Email&quot;</span><span class=\"mtk12\">:</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 class=\"mtk8\">&quot;Type&quot;</span><span class=\"mtk12\">:</span><span class=\"mtk1\"> </span><span class=\"mtk8\">&quot;Primary&quot;</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">                </span><span class=\"mtk8\">&quot;Value&quot;</span><span class=\"mtk12\">:</span><span class=\"mtk1\"> </span><span class=\"mtk12\">email</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 class=\"mtk1\">            </span><span class=\"mtk8\">&quot;Password&quot;</span><span class=\"mtk12\">:</span><span class=\"mtk1\"> </span><span class=\"mtk12\">password</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">     }</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">     </span><span class=\"mtk10\">console</span><span class=\"mtk1\">.</span><span class=\"mtk11\">log</span><span class=\"mtk1\">(</span><span class=\"mtk12\">signupFields</span><span class=\"mtk1\">)</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">   </span><span class=\"mtk4\">}</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">   const navigateToLogin=()=&gt;</span><span class=\"mtk4\">{}</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk17\">&lt;/</span><span class=\"mtk4\">script</span><span class=\"mtk17\">&gt;</span></span></code></pre>\n<p>Your <code>signupFields</code> object has a specific format because it aligns with the structure of your Signup API's request. It would make complete sense when you hook your Signup API here.</p>\n<p>Let's render the Signup component inside your <code>App.svelte</code> file:</p>\n<p><img src=\"/f70cc840f16f82553b479878867845f4/Signup-Page.png\" alt=\"Signup Page\"></p>\n<h2 id=\"the-home-component\" style=\"position:relative;\"><a href=\"#the-home-component\" aria-label=\"the home component 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>The Home Component</h2>\n<p>Let's create your Home component or the page where you'll redirect an user on a successfull login. Inside <code>/src/Home.svelte</code> file, add the following HTML:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"html\" data-index=\"13\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk1\">{#</span><span class=\"mtk15\">if</span><span class=\"mtk1\"> </span><span class=\"mtk12\">user</span><span class=\"mtk1\"> && </span><span class=\"mtk12\">_user</span><span class=\"mtk1\">}</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk17\">&lt;</span><span class=\"mtk4\">h3</span><span class=\"mtk17\">&gt;</span><span class=\"mtk1\">Welcome </span><span class=\"mtk4\">{</span><span class=\"mtk12\">_user</span><span class=\"mtk1\">?.</span><span class=\"mtk12\">profile</span><span class=\"mtk1\">?.</span><span class=\"mtk12\">FullName</span><span class=\"mtk4\">}</span><span class=\"mtk17\">&lt;/</span><span class=\"mtk4\">h3</span><span class=\"mtk17\">&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk17\">&lt;</span><span class=\"mtk4\">button</span><span class=\"mtk1\"> </span><span class=\"mtk12\">on</span><span class=\"mtk1\">:</span><span class=\"mtk12\">click</span><span class=\"mtk1\">=</span><span class=\"mtk8\">&quot;{logout}&quot;</span><span class=\"mtk17\">&gt;</span><span class=\"mtk1\">Logout</span><span class=\"mtk17\">&lt;/</span><span class=\"mtk4\">button</span><span class=\"mtk17\">&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">{/</span><span class=\"mtk15\">if</span><span class=\"mtk1\">}</span></span></code></pre>\n<p>In the above HTML, you simply use some Svelte conditionals to render the user's name and a logout button. The script part of your Home component looks like this:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"javascript\" data-index=\"14\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk17\">&lt;</span><span class=\"mtk4\">script</span><span class=\"mtk17\">&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    import </span><span class=\"mtk4\">{</span><span class=\"mtk12\">user</span><span class=\"mtk4\">}</span><span class=\"mtk1\"> from &#39;./stores&#39;;</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    let _user;</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    user.subscribe(data=&gt;_user=data)</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    const logout=()=&gt;</span><span class=\"mtk4\">{</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">        </span><span class=\"mtk12\">user</span><span class=\"mtk1\">.</span><span class=\"mtk11\">set</span><span class=\"mtk1\">(</span><span class=\"mtk4\">null</span><span class=\"mtk1\">);</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">        </span><span class=\"mtk12\">localStorage</span><span class=\"mtk1\">.</span><span class=\"mtk11\">clear</span><span class=\"mtk1\">();</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk4\">}</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk17\">&lt;/</span><span class=\"mtk4\">script</span><span class=\"mtk17\">&gt;</span></span></code></pre>\n<p>You import the global <code>user</code> object from your Svelte store and store it inside your Home component's state <code>_user</code>. For the <code>logout</code> function, you simply set this <code>user</code> object in your store to null and clear the local storage.</p>\n<h2 id=\"setup-loginradius\" style=\"position:relative;\"><a href=\"#setup-loginradius\" aria-label=\"setup 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>Setup LoginRadius</h2>\n<p>The next step is to set up LoginRadius, so you can start using its Authentication APIs from your Svelte App.</p>\n<h3 id=\"create-loginradius-account\" style=\"position:relative;\"><a href=\"#create-loginradius-account\" aria-label=\"create loginradius account 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>Create LoginRadius Account</h3>\n<p>Head over to <a href=\"https://accounts.loginradius.com/auth.aspx?plan=developer&#x26;action=register\">LoginRadius</a> and create a new account by filling in the following details:</p>\n<p><img src=\"/5f0a6c05fe8103a95752a598ff49cb06/Signup-2.png\" alt=\"Signup 2\"></p>\n<p>You'll then see a form with the name of your App, a URL, and a Data Center:</p>\n<p><img src=\"/d8b3b347f5c28460e05fcc3aeb364a90/Signup-3.png\" alt=\"Signup 3\"></p>\n<p>Hit <strong>Next</strong> and LoginRadius will set up an authentication app for you. You can try the pre-built authentication page LoginRadius provides for your app by clicking on <strong>Try Signing Up Now</strong>.</p>\n<p><img src=\"/4113757d959a0955ec852e781c5f1dad/Signup-4.png\" alt=\"Signup 4\"></p>\n<p>Once you do that, you'll be shown a pre-built authentication page of your LoginRadius app:</p>\n<p><img src=\"/294bf6ef8298c2248b922f708db69374/LoginRadius-Auth-Page.png\" alt=\"LoginRadius Auth Page\"></p>\n<p>However, for this tutorial, all you need are the LoginRadius APIs since you already have a frontend (your Svelte App) in place.</p>\n<h3 id=\"get-loginradius-api-configurations\" style=\"position:relative;\"><a href=\"#get-loginradius-api-configurations\" aria-label=\"get loginradius api configurations 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>Get LoginRadius API Configurations</h3>\n<p>Once you're inside your LoginRadius account, head over to the <strong>Configurations</strong> tab from your dashboard. Then expand the <strong>API Credentials</strong> tab of your application.</p>\n<p><img src=\"/2f2ec40982bff4f7b0ff5f1e2feb34e6/LoginRadius-Configuration-Tab.png\" alt=\"LoginRadius Configuration Tab\"></p>\n<p>Inside that, you should see your APP Name, API Key, and API Secret.</p>\n<p><img src=\"/f186d4d464190f4ab2407c896cb101be/LoginRadius-API-Credentials.png\" alt=\"LoginRadius API Credentials\"></p>\n<h3 id=\"add-api-credentials-as-environment-variables\" style=\"position:relative;\"><a href=\"#add-api-credentials-as-environment-variables\" aria-label=\"add api credentials as environment variables 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>Add API Credentials as Environment Variables</h3>\n<p>Head back to the Svelte App's <code>.env</code> file and add the above credentials inside it:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"15\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">APP_NAME=&lt;YOUR_APP_NAME&gt;</span>\n<span class=\"grvsc-line\">API_CLIENT_KEY= &lt;YOUR_APP_API_KEY&gt;</span>\n<span class=\"grvsc-line\">API_SECRET= &lt;YOUR_APP_API_SECRET&gt;</span></code></pre>\n<p>You'll need to ensure that the above <code>.env</code> file is present inside the <code>.gitignore</code> of your Svelte project. You don't want to accidentally push this file to a public repository on Github.</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"16\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">/node_modules/</span>\n<span class=\"grvsc-line\">/public/build/</span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\">.DS_Store</span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\">.env</span></code></pre>\n<h3 id=\"consume-environment-variables-in-svelte-components\" style=\"position:relative;\"><a href=\"#consume-environment-variables-in-svelte-components\" aria-label=\"consume environment variables in svelte components 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>Consume Environment Variables in Svelte Components</h3>\n<p>Finally, you need to extract these environment variables in your <code>sdkoptions</code> variables inside your App component file.</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"javascript\" data-index=\"17\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk1\">...</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">\t</span><span class=\"mtk4\">const</span><span class=\"mtk1\"> </span><span class=\"mtk12\">sdkoptions</span><span class=\"mtk1\"> = {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">\t</span><span class=\"mtk8\">&quot;apiKey&quot;</span><span class=\"mtk12\">:</span><span class=\"mtk1\"> </span><span class=\"mtk12\">__myapp</span><span class=\"mtk1\">[</span><span class=\"mtk8\">&quot;env&quot;</span><span class=\"mtk1\">].</span><span class=\"mtk12\">API_CLIENT_KEY</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">\t</span><span class=\"mtk8\">&quot;appName&quot;</span><span class=\"mtk12\">:__myapp</span><span class=\"mtk1\">[</span><span class=\"mtk8\">&quot;env&quot;</span><span class=\"mtk1\">].</span><span class=\"mtk12\">APP_NAME</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk8\">&quot;apiSecret&quot;</span><span class=\"mtk12\">:__myapp</span><span class=\"mtk1\">[</span><span class=\"mtk8\">&quot;env&quot;</span><span class=\"mtk1\">].</span><span class=\"mtk12\">API_SECRET</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">\t}</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">...</span></span></code></pre>\n<p>And pass this variable as props to both the Login and Signup component:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"html\" data-index=\"18\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk1\">...</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk17\">&lt;</span><span class=\"mtk10\">Login</span><span class=\"mtk1\"> </span><span class=\"mtk4\">{</span><span class=\"mtk12\">sdkoptions</span><span class=\"mtk4\">}</span><span class=\"mtk1\"> </span><span class=\"mtk17\">/&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk17\">&lt;</span><span class=\"mtk10\">Signup</span><span class=\"mtk1\"> </span><span class=\"mtk4\">{</span><span class=\"mtk12\">sdkoptions</span><span class=\"mtk4\">}</span><span class=\"mtk1\"> </span><span class=\"mtk17\">/&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">...</span></span></code></pre>\n<p>Great! Now you're ready to integrate LoginRadius APIs in your Svelte app.</p>\n<h2 id=\"integrate-loginradius-api\" style=\"position:relative;\"><a href=\"#integrate-loginradius-api\" aria-label=\"integrate loginradius 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>Integrate LoginRadius API</h2>\n<p>You'll use two APIs — one for registering the user on the Signup page and the other for authenticating the user on the Login Page. However, both APIs will take the API key and API secret as query parameters.</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"javascript\" data-index=\"19\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk4\">const</span><span class=\"mtk1\"> </span><span class=\"mtk12\">endpoint</span><span class=\"mtk1\"> = </span><span class=\"mtk8\">`</span><span class=\"mtk4\">${</span><span class=\"mtk12\">BASE_URL</span><span class=\"mtk4\">}</span><span class=\"mtk8\">?apikey=</span><span class=\"mtk4\">${</span><span class=\"mtk12\">sdkoptions</span><span class=\"mtk1\">.</span><span class=\"mtk12\">apiKey</span><span class=\"mtk4\">}</span><span class=\"mtk8\">&apisecret=</span><span class=\"mtk4\">${</span><span class=\"mtk12\">sdkoptions</span><span class=\"mtk1\">.</span><span class=\"mtk12\">apiSecret</span><span class=\"mtk4\">}</span><span class=\"mtk8\">`</span></span></code></pre>\n<p>So in the above endpoint, you'll only change the <code>BASE_URL</code> according to which API you're hitting.</p>\n<h3 id=\"integrate-signup-api\" style=\"position:relative;\"><a href=\"#integrate-signup-api\" aria-label=\"integrate signup 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>Integrate Signup API</h3>\n<p>Inside your <code>Signup.svelte</code> file, you'll create a variable called <code>signupResponse</code> to store the result of the Signup API. It also has properties like <code>success</code> and <code>error</code> to prompt the user on the status of your API calls.</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"javascript\" data-index=\"20\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk17\">&lt;</span><span class=\"mtk4\">script</span><span class=\"mtk17\">&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    let signupResponse=</span><span class=\"mtk4\">{</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">            </span><span class=\"mtk12\">success</span><span class=\"mtk1\">:</span><span class=\"mtk4\">null</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">            </span><span class=\"mtk12\">error</span><span class=\"mtk1\">:</span><span class=\"mtk4\">null</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">            </span><span class=\"mtk12\">uid</span><span class=\"mtk1\">:</span><span class=\"mtk4\">null</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">            </span><span class=\"mtk12\">id</span><span class=\"mtk1\">:</span><span class=\"mtk4\">null</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">            </span><span class=\"mtk12\">fullname</span><span class=\"mtk1\">:</span><span class=\"mtk4\">null</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">     </span><span class=\"mtk4\">}</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\"> \tlet loading;</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk17\">&lt;/</span><span class=\"mtk4\">script</span><span class=\"mtk17\">&gt;</span></span></code></pre>\n<p>Since an API request is an asynchronous process, you also have a' loading' variable to disable the submit button until the API responds.</p>\n<h4 id=\"signup-api-request-on-signup-form-submission\" style=\"position:relative;\"><a href=\"#signup-api-request-on-signup-form-submission\" aria-label=\"signup api request on signup form submission 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>Signup API Request on Signup Form Submission</h4>\n<p>You need to send a request to the Signup API inside your <code>handleSubmit()</code> function. First, set the <code>loading</code> to true and reset the <code>signupResponse</code> object. Then, use the fetch API to make a POST request with the <code>signupFields</code> object as post parameter:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"javascript\" data-index=\"21\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk4\">const</span><span class=\"mtk1\"> </span><span class=\"mtk11\">handleSubmit</span><span class=\"mtk1\"> = () </span><span class=\"mtk4\">=&gt;</span><span class=\"mtk1\"> {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  </span><span class=\"mtk4\">const</span><span class=\"mtk1\"> </span><span class=\"mtk12\">signupFields</span><span class=\"mtk1\"> = {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk12\">FirstName:</span><span class=\"mtk1\"> </span><span class=\"mtk12\">firstName</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk12\">LastName:</span><span class=\"mtk1\"> </span><span class=\"mtk12\">lastName</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk12\">Email:</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 class=\"mtk12\">Type:</span><span class=\"mtk1\"> </span><span class=\"mtk8\">&quot;Primary&quot;</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">        </span><span class=\"mtk12\">Value:</span><span class=\"mtk1\"> </span><span class=\"mtk12\">email</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 class=\"mtk1\">    </span><span class=\"mtk12\">Password:</span><span class=\"mtk1\"> </span><span class=\"mtk12\">password</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 class=\"mtk12\">loading</span><span class=\"mtk1\"> = </span><span class=\"mtk4\">true</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  </span><span class=\"mtk12\">signupResponse</span><span class=\"mtk1\"> = {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk12\">success:</span><span class=\"mtk1\"> </span><span class=\"mtk4\">null</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk12\">error:</span><span class=\"mtk1\"> </span><span class=\"mtk4\">null</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk12\">uid:</span><span class=\"mtk1\"> </span><span class=\"mtk4\">null</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk12\">id:</span><span class=\"mtk1\"> </span><span class=\"mtk4\">null</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk12\">fullname:</span><span class=\"mtk1\"> </span><span class=\"mtk4\">null</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 class=\"mtk4\">const</span><span class=\"mtk1\"> </span><span class=\"mtk12\">endpoint</span><span class=\"mtk1\"> = </span><span class=\"mtk8\">`https://api.loginradius.com/identity/v2/manage/account?apikey=</span><span class=\"mtk4\">${</span><span class=\"mtk12\">sdkoptions</span><span class=\"mtk1\">.</span><span class=\"mtk12\">apiKey</span><span class=\"mtk4\">}</span><span class=\"mtk8\">&apisecret=</span><span class=\"mtk4\">${</span><span class=\"mtk12\">sdkoptions</span><span class=\"mtk1\">.</span><span class=\"mtk12\">apiSecret</span><span class=\"mtk4\">}</span><span class=\"mtk8\">`</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  </span><span class=\"mtk11\">fetch</span><span class=\"mtk1\">(</span><span class=\"mtk12\">endpoint</span><span class=\"mtk1\">, {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk12\">method:</span><span class=\"mtk1\"> </span><span class=\"mtk8\">&quot;POST&quot;</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk12\">headers:</span><span class=\"mtk1\"> {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">      </span><span class=\"mtk8\">&quot;Content-Type&quot;</span><span class=\"mtk12\">:</span><span class=\"mtk1\"> </span><span class=\"mtk8\">&quot;application/json&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 class=\"mtk12\">body:</span><span class=\"mtk1\"> </span><span class=\"mtk10\">JSON</span><span class=\"mtk1\">.</span><span class=\"mtk11\">stringify</span><span class=\"mtk1\">(</span><span class=\"mtk12\">signupFields</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 class=\"mtk11\">then</span><span class=\"mtk1\">(</span><span class=\"mtk12\">response</span><span class=\"mtk1\"> </span><span class=\"mtk4\">=&gt;</span><span class=\"mtk1\"> </span><span class=\"mtk12\">response</span><span class=\"mtk1\">.</span><span class=\"mtk11\">json</span><span class=\"mtk1\">())</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    .</span><span class=\"mtk11\">then</span><span class=\"mtk1\">(</span><span class=\"mtk12\">data</span><span class=\"mtk1\"> </span><span class=\"mtk4\">=&gt;</span><span class=\"mtk1\"> {})</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    .</span><span class=\"mtk11\">catch</span><span class=\"mtk1\">(</span><span class=\"mtk12\">error</span><span class=\"mtk1\"> </span><span class=\"mtk4\">=&gt;</span><span class=\"mtk1\"> </span><span class=\"mtk10\">console</span><span class=\"mtk1\">.</span><span class=\"mtk11\">log</span><span class=\"mtk1\">(</span><span class=\"mtk12\">error</span><span class=\"mtk1\">))</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    .</span><span class=\"mtk11\">finally</span><span class=\"mtk1\">(() </span><span class=\"mtk4\">=&gt;</span><span class=\"mtk1\"> (</span><span class=\"mtk12\">loading</span><span class=\"mtk1\"> = </span><span class=\"mtk4\">false</span><span class=\"mtk1\">))</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">}</span></span></code></pre>\n<h4 id=\"handle-api-response\" style=\"position:relative;\"><a href=\"#handle-api-response\" aria-label=\"handle api 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>Handle API Response</h4>\n<p>Inside the callback of your fetch request, you can handle any errors returned by the API based on different error codes. In case of success, you'll populate your <code>signupResponse</code> object with data from the API. In the <code>finally</code> block, set the <code>loading</code> to false.</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"javascript\" data-index=\"22\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk1\">...</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">.</span><span class=\"mtk11\">then</span><span class=\"mtk1\">(</span><span class=\"mtk12\">data</span><span class=\"mtk4\">=&gt;</span><span class=\"mtk1\">{</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">          </span><span class=\"mtk15\">if</span><span class=\"mtk1\">(</span><span class=\"mtk12\">data</span><span class=\"mtk1\">.</span><span class=\"mtk12\">ErrorCode</span><span class=\"mtk1\">){</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">              </span><span class=\"mtk15\">if</span><span class=\"mtk1\">(</span><span class=\"mtk12\">data</span><span class=\"mtk1\">.</span><span class=\"mtk12\">ErrorCode</span><span class=\"mtk1\">==</span><span class=\"mtk7\">936</span><span class=\"mtk1\">){</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">              </span><span class=\"mtk12\">signupResponse</span><span class=\"mtk1\">={</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">                    ...</span><span class=\"mtk12\">signupResponse</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">                    </span><span class=\"mtk12\">error:data</span><span class=\"mtk1\">.</span><span class=\"mtk12\">Message</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 class=\"mtk1\">            </span><span class=\"mtk15\">else</span><span class=\"mtk1\"> </span><span class=\"mtk15\">if</span><span class=\"mtk1\">(</span><span class=\"mtk12\">data</span><span class=\"mtk1\">.</span><span class=\"mtk12\">ErrorCode</span><span class=\"mtk1\">==</span><span class=\"mtk7\">1134</span><span class=\"mtk1\">){</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">                </span><span class=\"mtk12\">signupResponse</span><span class=\"mtk1\">={</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">                    ...</span><span class=\"mtk12\">signupResponse</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">                    </span><span class=\"mtk12\">error:data</span><span class=\"mtk1\">.</span><span class=\"mtk12\">Errors</span><span class=\"mtk1\">[</span><span class=\"mtk7\">0</span><span class=\"mtk1\">].</span><span class=\"mtk12\">ErrorMessage</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">                }</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">            }</span><span class=\"mtk15\">else</span><span class=\"mtk1\">{</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">                </span><span class=\"mtk12\">signupResponse</span><span class=\"mtk1\">={</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">                    ...</span><span class=\"mtk12\">signupResponse</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">                    </span><span class=\"mtk12\">error:data</span><span class=\"mtk1\">.</span><span class=\"mtk12\">Description</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 class=\"mtk1\">        }</span><span class=\"mtk15\">else</span><span class=\"mtk1\">{</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">            </span><span class=\"mtk12\">signupResponse</span><span class=\"mtk1\">={</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">                ...</span><span class=\"mtk12\">signupResponse</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">                </span><span class=\"mtk12\">success:</span><span class=\"mtk8\">&quot;Account created successfully! Please login via the same details.&quot;</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">                </span><span class=\"mtk12\">fullname:data</span><span class=\"mtk1\">.</span><span class=\"mtk12\">FullName</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">                </span><span class=\"mtk12\">id:data</span><span class=\"mtk1\">.</span><span class=\"mtk12\">id</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">                </span><span class=\"mtk12\">uid:data</span><span class=\"mtk1\">.</span><span class=\"mtk12\">Uid</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 class=\"mtk1\">      })</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">...</span></span></code></pre>\n<h4 id=\"disable-submit-button\" style=\"position:relative;\"><a href=\"#disable-submit-button\" aria-label=\"disable submit button 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>Disable Submit Button</h4>\n<p>You can set the disabled attribute on your Submit button based on the loading state of the API.</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"html\" data-index=\"23\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk1\">...</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk17\">&lt;</span><span class=\"mtk4\">button</span><span class=\"mtk1\"> </span><span class=\"mtk12\">disabled</span><span class=\"mtk1\">=</span><span class=\"mtk8\">&quot;{loading}&quot;</span><span class=\"mtk1\"> </span><span class=\"mtk12\">class</span><span class=\"mtk1\">=</span><span class=\"mtk8\">&quot;form-field&quot;</span><span class=\"mtk17\">&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  Signup</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk17\">&lt;/</span><span class=\"mtk4\">button</span><span class=\"mtk17\">&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">...</span></span></code></pre>\n<h4 id=\"show-signup-success-and-error\" style=\"position:relative;\"><a href=\"#show-signup-success-and-error\" aria-label=\"show signup success and error 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>Show Signup Success and Error</h4>\n<p>Lastly, render a conditional template based on the status of your Signup API.</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"html\" data-index=\"24\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk1\">... {#</span><span class=\"mtk15\">if</span><span class=\"mtk1\"> </span><span class=\"mtk12\">signupResponse</span><span class=\"mtk1\">.</span><span class=\"mtk12\">error</span><span class=\"mtk1\">}</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk17\">&lt;</span><span class=\"mtk4\">p</span><span class=\"mtk1\"> </span><span class=\"mtk12\">class</span><span class=\"mtk1\">=</span><span class=\"mtk8\">&quot;error&quot;</span><span class=\"mtk17\">&gt;</span><span class=\"mtk1\">Error ❌ </span><span class=\"mtk4\">{</span><span class=\"mtk12\">signupResponse</span><span class=\"mtk1\">.</span><span class=\"mtk12\">error</span><span class=\"mtk4\">}</span><span class=\"mtk17\">&lt;/</span><span class=\"mtk4\">p</span><span class=\"mtk17\">&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">{/</span><span class=\"mtk15\">if</span><span class=\"mtk1\">} {#</span><span class=\"mtk15\">if</span><span class=\"mtk1\"> </span><span class=\"mtk12\">signupResponse</span><span class=\"mtk1\">.</span><span class=\"mtk12\">success</span><span class=\"mtk1\">}</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk17\">&lt;</span><span class=\"mtk4\">p</span><span class=\"mtk1\"> </span><span class=\"mtk12\">class</span><span class=\"mtk1\">=</span><span class=\"mtk8\">&quot;success&quot;</span><span class=\"mtk17\">&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  Success ✔ </span><span class=\"mtk4\">{</span><span class=\"mtk12\">signupResponse</span><span class=\"mtk1\">.</span><span class=\"mtk12\">success</span><span class=\"mtk4\">}</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk17\">&lt;/</span><span class=\"mtk4\">p</span><span class=\"mtk17\">&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">{/</span><span class=\"mtk15\">if</span><span class=\"mtk1\">} ...</span></span></code></pre>\n<p>And that's it! Let's give your Signup functionality a whirl. Create a new account first:</p>\n<p><img src=\"/1ec6121e723d287acd3097bcf72a8fe8/Signup-Success-with-API.png\" alt=\"Signup Success with API\"></p>\n<p>And voila! You can see in the network tab that the API is successful. And you got back a bunch of data about the newly created user. You also have a success that appears underneath the Signup form.</p>\n<p>Let's also test an erroneous flow. What if you signup via the same credentials again?</p>\n<p><img src=\"/332563b5257d0cf45b9ae3039ea0a832/Signup-Failure-Existing-Email.png\" alt=\"Signup Failure Existing Email\"></p>\n<p>The LoginRadius Signup API returns the error message, details, error code, etc., that you've handled accordingly.</p>\n<p>Also, if you use a simple password, the LoginRadius API returns an error based on a validation mechanism.</p>\n<p><img src=\"/af70d87365d494ebae97ec028b47d597/Signup-Error-Password-Validation.png\" alt=\"Signup Error Password Validation\"></p>\n<p>That's great because it makes your authentication workflow more air-tight.</p>\n<h3 id=\"integrate-login-api\" style=\"position:relative;\"><a href=\"#integrate-login-api\" aria-label=\"integrate login 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>Integrate Login API</h3>\n<p>Similarly, you can now integrate the Login API as well in your <code>Login.svelte</code> file:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"javascript\" data-index=\"25\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk17\">&lt;</span><span class=\"mtk4\">script</span><span class=\"mtk17\">&gt;</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">\t...</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    import </span><span class=\"mtk4\">{</span><span class=\"mtk12\">user</span><span class=\"mtk4\">}</span><span class=\"mtk1\"> from &#39;./stores&#39;;</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    let email;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    let password;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    let loading;</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    let loginResponse=</span><span class=\"mtk4\">{</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">        </span><span class=\"mtk12\">error</span><span class=\"mtk1\">:</span><span class=\"mtk4\">null</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">        </span><span class=\"mtk12\">success</span><span class=\"mtk1\">:</span><span class=\"mtk4\">null</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">        </span><span class=\"mtk12\">profile</span><span class=\"mtk1\">:</span><span class=\"mtk4\">null</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">        </span><span class=\"mtk12\">auth_token</span><span class=\"mtk1\">:</span><span class=\"mtk4\">null</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk4\">}</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    export let sdkoptions;</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    const handleSubmit=(e)=&gt;</span><span class=\"mtk4\">{</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">       </span><span class=\"mtk12\">let</span><span class=\"mtk1\"> </span><span class=\"mtk12\">loginFields</span><span class=\"mtk1\">={</span><span class=\"mtk12\">email</span><span class=\"mtk1\">,</span><span class=\"mtk12\">password</span><span class=\"mtk1\">};</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">       </span><span class=\"mtk12\">loading</span><span class=\"mtk1\">=</span><span class=\"mtk4\">true</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">        </span><span class=\"mtk12\">loginResponse</span><span class=\"mtk1\">={</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">        </span><span class=\"mtk12\">error:</span><span class=\"mtk4\">null</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">        </span><span class=\"mtk12\">success:</span><span class=\"mtk4\">null</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">        </span><span class=\"mtk12\">profile:</span><span class=\"mtk4\">null</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">        </span><span class=\"mtk12\">auth_token:</span><span class=\"mtk4\">null</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    }</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">       </span><span class=\"mtk12\">const</span><span class=\"mtk1\"> </span><span class=\"mtk12\">endpoint</span><span class=\"mtk1\">=</span><span class=\"mtk8\">`https://api.loginradius.com/identity/v2/auth/login?apikey=</span><span class=\"mtk4\">${</span><span class=\"mtk12\">sdkoptions</span><span class=\"mtk1\">.</span><span class=\"mtk12\">apiKey</span><span class=\"mtk4\">}</span><span class=\"mtk8\">&apisecret=</span><span class=\"mtk4\">${</span><span class=\"mtk12\">sdkoptions</span><span class=\"mtk1\">.</span><span class=\"mtk12\">apiSecret</span><span class=\"mtk4\">}</span><span class=\"mtk8\">`</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">       </span><span class=\"mtk12\">loading</span><span class=\"mtk1\">=</span><span class=\"mtk4\">true</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk11\">fetch</span><span class=\"mtk1\">(</span><span class=\"mtk12\">endpoint</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 class=\"mtk12\">method:</span><span class=\"mtk8\">&#39;POST&#39;</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">        </span><span class=\"mtk12\">headers:</span><span class=\"mtk1\"> {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">        </span><span class=\"mtk8\">&#39;Content-Type&#39;</span><span class=\"mtk12\">:</span><span class=\"mtk1\"> </span><span class=\"mtk8\">&#39;application/json&#39;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">        },</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">        </span><span class=\"mtk12\">body:</span><span class=\"mtk10\">JSON</span><span class=\"mtk1\">.</span><span class=\"mtk11\">stringify</span><span class=\"mtk1\">(</span><span class=\"mtk12\">loginFields</span><span class=\"mtk1\">)</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">        }).</span><span class=\"mtk11\">then</span><span class=\"mtk1\">(</span><span class=\"mtk12\">response</span><span class=\"mtk4\">=&gt;</span><span class=\"mtk12\">response</span><span class=\"mtk1\">.</span><span class=\"mtk11\">json</span><span class=\"mtk1\">())</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">        .</span><span class=\"mtk11\">then</span><span class=\"mtk1\">(</span><span class=\"mtk12\">data</span><span class=\"mtk4\">=&gt;</span><span class=\"mtk1\">{</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">            </span><span class=\"mtk10\">console</span><span class=\"mtk1\">.</span><span class=\"mtk11\">log</span><span class=\"mtk1\">(</span><span class=\"mtk12\">data</span><span class=\"mtk1\">)</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">            </span><span class=\"mtk15\">if</span><span class=\"mtk1\">(</span><span class=\"mtk12\">data</span><span class=\"mtk1\">.</span><span class=\"mtk12\">ErrorCode</span><span class=\"mtk1\">){</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">                </span><span class=\"mtk15\">if</span><span class=\"mtk1\">(</span><span class=\"mtk12\">data</span><span class=\"mtk1\">.</span><span class=\"mtk12\">ErrorCode</span><span class=\"mtk1\">==</span><span class=\"mtk7\">936</span><span class=\"mtk1\">){</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">                </span><span class=\"mtk12\">loginResponse</span><span class=\"mtk1\">={</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">                        ...</span><span class=\"mtk12\">loginResponse</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">                        </span><span class=\"mtk12\">error:data</span><span class=\"mtk1\">.</span><span class=\"mtk12\">Message</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 class=\"mtk1\">                </span><span class=\"mtk15\">else</span><span class=\"mtk1\"> </span><span class=\"mtk15\">if</span><span class=\"mtk1\">(</span><span class=\"mtk12\">data</span><span class=\"mtk1\">.</span><span class=\"mtk12\">ErrorCode</span><span class=\"mtk1\">==</span><span class=\"mtk7\">1134</span><span class=\"mtk1\">){</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">                    </span><span class=\"mtk12\">loginResponse</span><span class=\"mtk1\">={</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">                        ...</span><span class=\"mtk12\">loginResponse</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">                        </span><span class=\"mtk12\">error:data</span><span class=\"mtk1\">.</span><span class=\"mtk12\">Errors</span><span class=\"mtk1\">[</span><span class=\"mtk7\">0</span><span class=\"mtk1\">].</span><span class=\"mtk12\">ErrorMessage</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">                    }</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">                }</span><span class=\"mtk15\">else</span><span class=\"mtk1\">{</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">                    </span><span class=\"mtk12\">loginResponse</span><span class=\"mtk1\">={</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">                        ...</span><span class=\"mtk12\">loginResponse</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">                        </span><span class=\"mtk12\">error:data</span><span class=\"mtk1\">.</span><span class=\"mtk12\">Description</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 class=\"mtk1\">            }</span><span class=\"mtk15\">else</span><span class=\"mtk1\">{</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">                </span><span class=\"mtk12\">loginResponse</span><span class=\"mtk1\">={</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">                    ...</span><span class=\"mtk12\">loginResponse</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">                    </span><span class=\"mtk12\">success:</span><span class=\"mtk4\">true</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">                    </span><span class=\"mtk12\">profile:data</span><span class=\"mtk1\">.</span><span class=\"mtk12\">Profile</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">                    </span><span class=\"mtk12\">auth_token:</span><span class=\"mtk1\">{</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">                        </span><span class=\"mtk12\">access_token:data</span><span class=\"mtk1\">.</span><span class=\"mtk12\">access_token</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">                        </span><span class=\"mtk12\">refresh_token:data</span><span class=\"mtk1\">.</span><span class=\"mtk12\">refresh_token</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">                        </span><span class=\"mtk12\">ttl:data</span><span class=\"mtk1\">.</span><span class=\"mtk12\">expires_in</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 class=\"mtk1\">                </span><span class=\"mtk12\">user</span><span class=\"mtk1\">.</span><span class=\"mtk11\">set</span><span class=\"mtk1\">(</span><span class=\"mtk12\">loginResponse</span><span class=\"mtk1\">)</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">                </span><span class=\"mtk12\">localStorage</span><span class=\"mtk1\">.</span><span class=\"mtk11\">setItem</span><span class=\"mtk1\">(</span><span class=\"mtk8\">&#39;user&#39;</span><span class=\"mtk1\">,</span><span class=\"mtk10\">JSON</span><span class=\"mtk1\">.</span><span class=\"mtk11\">stringify</span><span class=\"mtk1\">(</span><span class=\"mtk12\">loginResponse</span><span class=\"mtk1\">))</span></span>\n<span class=\"grvsc-line\"></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 class=\"mtk1\">        .</span><span class=\"mtk11\">catch</span><span class=\"mtk1\">(</span><span class=\"mtk12\">error</span><span class=\"mtk4\">=&gt;</span><span class=\"mtk10\">console</span><span class=\"mtk1\">.</span><span class=\"mtk11\">log</span><span class=\"mtk1\">(</span><span class=\"mtk12\">error</span><span class=\"mtk1\">))</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">        .</span><span class=\"mtk11\">finally</span><span class=\"mtk1\">(()</span><span class=\"mtk4\">=&gt;</span><span class=\"mtk12\">loading</span><span class=\"mtk1\">=</span><span class=\"mtk4\">false</span><span class=\"mtk1\">);</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk4\">}</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=\"mtk17\">&lt;/</span><span class=\"mtk4\">script</span><span class=\"mtk17\">&gt;</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">...</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">{#</span><span class=\"mtk15\">if</span><span class=\"mtk1\"> </span><span class=\"mtk12\">loginResponse</span><span class=\"mtk1\">.</span><span class=\"mtk12\">error</span><span class=\"mtk1\">}</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">\t</span><span class=\"mtk17\">&lt;</span><span class=\"mtk4\">p</span><span class=\"mtk1\"> </span><span class=\"mtk12\">class</span><span class=\"mtk1\">=</span><span class=\"mtk8\">&quot;error&quot;</span><span class=\"mtk17\">&gt;</span><span class=\"mtk1\">Error ❌ </span><span class=\"mtk4\">{</span><span class=\"mtk12\">loginResponse</span><span class=\"mtk1\">.</span><span class=\"mtk12\">error</span><span class=\"mtk4\">}</span><span class=\"mtk17\">&lt;/</span><span class=\"mtk4\">p</span><span class=\"mtk17\">&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">{/</span><span class=\"mtk15\">if</span><span class=\"mtk1\">}</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">{#</span><span class=\"mtk15\">if</span><span class=\"mtk1\"> </span><span class=\"mtk12\">loginResponse</span><span class=\"mtk1\">.</span><span class=\"mtk12\">success</span><span class=\"mtk1\">}</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">\t</span><span class=\"mtk17\">&lt;</span><span class=\"mtk4\">p</span><span class=\"mtk1\"> </span><span class=\"mtk12\">class</span><span class=\"mtk1\">=</span><span class=\"mtk8\">&quot;success&quot;</span><span class=\"mtk17\">&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">        Success ✔</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk17\">&lt;/</span><span class=\"mtk4\">p</span><span class=\"mtk17\">&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">{/</span><span class=\"mtk15\">if</span><span class=\"mtk1\">}</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk17\">&lt;</span><span class=\"mtk4\">p</span><span class=\"mtk17\">&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    Don&#39;t have an account?</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk17\">&lt;</span><span class=\"mtk4\">strong</span><span class=\"mtk1\"> </span><span class=\"mtk12\">class</span><span class=\"mtk1\">=</span><span class=\"mtk8\">&quot;link&quot;</span><span class=\"mtk1\"> </span><span class=\"mtk12\">on</span><span class=\"mtk1\">:</span><span class=\"mtk12\">click</span><span class=\"mtk1\">=</span><span class=\"mtk4\">{</span><span class=\"mtk12\">navigateToSignup</span><span class=\"mtk4\">}</span><span class=\"mtk17\">&gt;</span><span class=\"mtk1\">Sign up</span><span class=\"mtk17\">&lt;/</span><span class=\"mtk4\">strong</span><span class=\"mtk17\">&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk17\">&lt;/</span><span class=\"mtk4\">p</span><span class=\"mtk17\">&gt;</span></span></code></pre>\n<p>If you relate it to the Signup component, it's almost identical. The only thing that has changed is the API endpoint. Additionally, if the Login API is a success, you're also storing the data in your <code>user</code> store and consequently updating your <code>localStorage</code>.</p>\n<p>Let's also test this out:</p>\n<p><img src=\"/4bb4c7881a3e1accbb0b996f7bed9b77/Login-API-Success.png\" alt=\"Login API Success\"></p>\n<p>Let's also test an erroneous Login flow by entering the credentials for a user that doesn't exist:</p>\n<p><img src=\"/5b4dd5cb3d6ed27fc288aff238ded14f/Login-Error.png\" alt=\"Login Error\"></p>\n<p>Great! Let's now tie all these individual pages together by setting up routing in your Svelte app.</p>\n<h2 id=\"setup-routes\" style=\"position:relative;\"><a href=\"#setup-routes\" aria-label=\"setup routes 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>Setup Routes</h2>\n<p>You'll use the <code>svelte-navigator</code> package that you previously installed to configure routing in your app.</p>\n<h3 id=\"add-routing\" style=\"position:relative;\"><a href=\"#add-routing\" aria-label=\"add routing 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>Add Routing</h3>\n<p>First, you'll define the routes for the Signup, Login, and Home pages inside your <code>App.svelte</code> file:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"html\" data-index=\"26\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk17\">&lt;</span><span class=\"mtk4\">script</span><span class=\"mtk17\">&gt;</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  /** IMPORTS */</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  import </span><span class=\"mtk4\">{</span><span class=\"mtk1\"> </span><span class=\"mtk12\">Router</span><span class=\"mtk1\">, </span><span class=\"mtk12\">Route</span><span class=\"mtk1\"> </span><span class=\"mtk4\">}</span><span class=\"mtk1\"> from &quot;svelte-navigator&quot;;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  ...</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk17\">&lt;/</span><span class=\"mtk4\">script</span><span class=\"mtk17\">&gt;</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk17\">&lt;</span><span class=\"mtk4\">main</span><span class=\"mtk17\">&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  </span><span class=\"mtk17\">&lt;</span><span class=\"mtk10\">Router</span><span class=\"mtk17\">&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk17\">&lt;</span><span class=\"mtk4\">div</span><span class=\"mtk17\">&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">      </span><span class=\"mtk17\">&lt;</span><span class=\"mtk10\">Route</span><span class=\"mtk1\"> </span><span class=\"mtk12\">path</span><span class=\"mtk1\">=</span><span class=\"mtk8\">&quot;signup&quot;</span><span class=\"mtk17\">&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">        </span><span class=\"mtk17\">&lt;</span><span class=\"mtk10\">Signup</span><span class=\"mtk1\"> </span><span class=\"mtk4\">{</span><span class=\"mtk12\">sdkoptions</span><span class=\"mtk4\">}</span><span class=\"mtk1\"> </span><span class=\"mtk17\">/&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">      </span><span class=\"mtk17\">&lt;/</span><span class=\"mtk10\">Route</span><span class=\"mtk17\">&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">      </span><span class=\"mtk17\">&lt;</span><span class=\"mtk10\">Route</span><span class=\"mtk1\"> </span><span class=\"mtk12\">path</span><span class=\"mtk1\">=</span><span class=\"mtk8\">&quot;login&quot;</span><span class=\"mtk17\">&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">        </span><span class=\"mtk17\">&lt;</span><span class=\"mtk10\">Login</span><span class=\"mtk1\"> </span><span class=\"mtk4\">{</span><span class=\"mtk12\">sdkoptions</span><span class=\"mtk4\">}</span><span class=\"mtk1\"> </span><span class=\"mtk17\">/&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">      </span><span class=\"mtk17\">&lt;/</span><span class=\"mtk10\">Route</span><span class=\"mtk17\">&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">      </span><span class=\"mtk17\">&lt;</span><span class=\"mtk10\">Route</span><span class=\"mtk1\"> </span><span class=\"mtk12\">path</span><span class=\"mtk1\">=</span><span class=\"mtk8\">&quot;/&quot;</span><span class=\"mtk17\">&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">        </span><span class=\"mtk17\">&lt;</span><span class=\"mtk10\">Home</span><span class=\"mtk1\"> </span><span class=\"mtk17\">/&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">      </span><span class=\"mtk17\">&lt;/</span><span class=\"mtk10\">Route</span><span class=\"mtk17\">&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk17\">&lt;/</span><span class=\"mtk4\">div</span><span class=\"mtk17\">&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  </span><span class=\"mtk17\">&lt;/</span><span class=\"mtk10\">Router</span><span class=\"mtk17\">&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk17\">&lt;/</span><span class=\"mtk4\">main</span><span class=\"mtk17\">&gt;</span></span></code></pre>\n<p>If you visit <code>/login</code>, you should see the Login Page. Similarly, if you go to <code>/signup</code>, you should see the Signup Page.</p>\n<h3 id=\"programmatic-redirection\" style=\"position:relative;\"><a href=\"#programmatic-redirection\" aria-label=\"programmatic redirection 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>Programmatic Redirection</h3>\n<p>Remember, you had a link to the Signup page at the bottom of the Login page and vice versa?</p>\n<p>Also, your login page doesn't redirect anywhere after you login successfully. In order to programmatically navigate to a specific page on completion of an action, you can use the <code>useNavigate</code> hook from the <code>svelte-navigator</code> library.</p>\n<p>To use this hook, import <code>useNavigate</code> and save its invoked reference inside a variable, as follows:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"javascript\" data-index=\"27\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk17\">&lt;</span><span class=\"mtk4\">script</span><span class=\"mtk17\">&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  import </span><span class=\"mtk4\">{</span><span class=\"mtk12\">useNavigate</span><span class=\"mtk4\">}</span><span class=\"mtk1\"> from &quot;svelte-navigator&quot;; const navigate = useNavigate();</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  ...</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk17\">&lt;/</span><span class=\"mtk4\">script</span><span class=\"mtk17\">&gt;</span></span></code></pre>\n<p>Now call the <code>navigate()</code> function and pass the path of the page you wish to redirect to. So let's complete the <code>navigateToLogin</code> function inside your Signup component:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"javascript\" data-index=\"28\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk17\">&lt;</span><span class=\"mtk4\">script</span><span class=\"mtk17\">&gt;</span><span class=\"mtk1\">... const navigateToLogin=()=&gt;navigate(&#39;/login&#39;); ...</span><span class=\"mtk17\">&lt;/</span><span class=\"mtk4\">script</span><span class=\"mtk17\">&gt;</span></span></code></pre>\n<p>Similarly, you can also complete the <code>navigateToSignup</code> function inside your Login component:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"javascript\" data-index=\"29\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk17\">&lt;</span><span class=\"mtk4\">script</span><span class=\"mtk17\">&gt;</span><span class=\"mtk1\">... const navigateToSignup=()=&gt;navigate(&#39;/signup&#39;) ...</span><span class=\"mtk17\">&lt;/</span><span class=\"mtk4\">script</span><span class=\"mtk17\">&gt;</span></span></code></pre>\n<p>Finally, you'll also navigate to the Home page on a successful response from your Login API inside your Login component's <code>handleSubmit</code> function:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"javascript\" data-index=\"30\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk1\"> </span><span class=\"mtk4\">const</span><span class=\"mtk1\"> </span><span class=\"mtk11\">handleSubmit</span><span class=\"mtk1\">=(</span><span class=\"mtk12\">e</span><span class=\"mtk1\">)</span><span class=\"mtk4\">=&gt;</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 class=\"mtk11\">fetch</span><span class=\"mtk1\">(</span><span class=\"mtk12\">endpoint</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 class=\"mtk11\">then</span><span class=\"mtk1\">(</span><span class=\"mtk12\">data</span><span class=\"mtk4\">=&gt;</span><span class=\"mtk1\">{</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\"> \t\t\t\t...</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">            }</span><span class=\"mtk12\">else</span><span class=\"mtk1\">{</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">\t\t\t\t...</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">                </span><span class=\"mtk11\">navigate</span><span class=\"mtk1\">(</span><span class=\"mtk8\">&#39;/&#39;</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 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=\"mtk1\">&lt;/</span><span class=\"mtk12\">script</span><span class=\"mtk1\">&gt;</span></span></code></pre>\n<p>Great! You can now navigate from your Login page to the Signup page and vice versa. You should also be automatically redirected to the Home page on a successful login.</p>\n<h3 id=\"add-protectedprivate-routes\" style=\"position:relative;\"><a href=\"#add-protectedprivate-routes\" aria-label=\"add protectedprivate routes 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>Add Protected/Private Routes</h3>\n<p>If you try to visit the Home component by entering the path <code>/</code> in the URL, you'll be able to see the Home page regardless of your authenticated state. However, you must protect this route so that it's only accessible to authenticated users in your application.</p>\n<p>For this purpose, you have created a <code>RouteGuard.svelte</code> file inside your <code>routes</code> folder. It's a higher-order component that uses the <code>useNavigation</code> hook to programmatically redirect to the login page if an unauthenticated user visits the home page. You use the <code>user</code> object from your Svelte store to validate the authenticated state of a user.</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"javascript\" data-index=\"31\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk17\">&lt;</span><span class=\"mtk4\">script</span><span class=\"mtk17\">&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    import </span><span class=\"mtk4\">{</span><span class=\"mtk1\"> </span><span class=\"mtk12\">useNavigate</span><span class=\"mtk1\">, </span><span class=\"mtk12\">useLocation</span><span class=\"mtk1\"> </span><span class=\"mtk4\">}</span><span class=\"mtk1\"> from &quot;svelte-navigator&quot;;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    import </span><span class=\"mtk4\">{</span><span class=\"mtk1\"> </span><span class=\"mtk12\">user</span><span class=\"mtk1\"> </span><span class=\"mtk4\">}</span><span class=\"mtk1\"> from &quot;../stores&quot;;</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    const navigate = useNavigate();</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    const location = useLocation();</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    $: if (!$user) </span><span class=\"mtk4\">{</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">      </span><span class=\"mtk11\">navigate</span><span class=\"mtk1\">(</span><span class=\"mtk8\">&quot;/login&quot;</span><span class=\"mtk1\">, {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">        </span><span class=\"mtk12\">state:</span><span class=\"mtk1\"> { </span><span class=\"mtk12\">from:</span><span class=\"mtk1\"> </span><span class=\"mtk12\">$location</span><span class=\"mtk1\">.</span><span class=\"mtk12\">pathname</span><span class=\"mtk1\"> },</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">        </span><span class=\"mtk12\">replace:</span><span class=\"mtk1\"> </span><span class=\"mtk4\">true</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 class=\"mtk4\">}</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  </span><span class=\"mtk17\">&lt;/</span><span class=\"mtk4\">script</span><span class=\"mtk17\">&gt;</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  {#</span><span class=\"mtk15\">if</span><span class=\"mtk1\"> </span><span class=\"mtk12\">$user</span><span class=\"mtk1\">}</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk17\">&lt;</span><span class=\"mtk4\">slot</span><span class=\"mtk1\"> </span><span class=\"mtk17\">/&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  {/</span><span class=\"mtk15\">if</span><span class=\"mtk1\">}</span></span></code></pre>\n<p>You can then wrap another higher order Route component on top of the <code>RouteGuard</code> component inside the <code>PrivateRoutes.svelte</code> file, as follows:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"javascript\" data-index=\"32\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk17\">&lt;</span><span class=\"mtk4\">script</span><span class=\"mtk17\">&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    import </span><span class=\"mtk4\">{</span><span class=\"mtk1\"> </span><span class=\"mtk12\">Route</span><span class=\"mtk1\"> </span><span class=\"mtk4\">}</span><span class=\"mtk1\"> from &quot;svelte-navigator&quot;;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    import RouteGuard from &quot;./RouteGuard.svelte&quot;;</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    export let path;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  </span><span class=\"mtk17\">&lt;/</span><span class=\"mtk4\">script</span><span class=\"mtk17\">&gt;</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  </span><span class=\"mtk17\">&lt;</span><span class=\"mtk10\">Route</span><span class=\"mtk1\"> </span><span class=\"mtk4\">{</span><span class=\"mtk12\">path</span><span class=\"mtk4\">}</span><span class=\"mtk1\"> </span><span class=\"mtk12\">let</span><span class=\"mtk1\">:</span><span class=\"mtk12\">params</span><span class=\"mtk1\"> </span><span class=\"mtk12\">let</span><span class=\"mtk1\">:</span><span class=\"mtk12\">location</span><span class=\"mtk1\"> </span><span class=\"mtk12\">let</span><span class=\"mtk1\">:</span><span class=\"mtk12\">navigate</span><span class=\"mtk17\">&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk17\">&lt;</span><span class=\"mtk10\">RouteGuard</span><span class=\"mtk17\">&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">      </span><span class=\"mtk17\">&lt;</span><span class=\"mtk4\">slot</span><span class=\"mtk1\"> </span><span class=\"mtk4\">{</span><span class=\"mtk12\">params</span><span class=\"mtk4\">}</span><span class=\"mtk1\"> </span><span class=\"mtk4\">{</span><span class=\"mtk12\">location</span><span class=\"mtk4\">}</span><span class=\"mtk1\"> </span><span class=\"mtk4\">{</span><span class=\"mtk12\">navigate</span><span class=\"mtk4\">}</span><span class=\"mtk1\"> </span><span class=\"mtk17\">/&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk17\">&lt;/</span><span class=\"mtk10\">RouteGuard</span><span class=\"mtk17\">&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  </span><span class=\"mtk17\">&lt;/</span><span class=\"mtk10\">Route</span><span class=\"mtk17\">&gt;</span></span></code></pre>\n<p>Now, all you need to do is use this <code>PrivateRoute</code> component to wrap your Home component instead of a regular Route component:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"javascript\" data-index=\"33\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk1\">...</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">\t</span><span class=\"mtk17\">&lt;</span><span class=\"mtk10\">PrivateRoute</span><span class=\"mtk1\"> </span><span class=\"mtk12\">path</span><span class=\"mtk1\">=</span><span class=\"mtk8\">&quot;/&quot;</span><span class=\"mtk1\"> </span><span class=\"mtk12\">let</span><span class=\"mtk1\">:</span><span class=\"mtk12\">location</span><span class=\"mtk17\">&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">\t\t</span><span class=\"mtk17\">&lt;</span><span class=\"mtk10\">Home</span><span class=\"mtk1\"> </span><span class=\"mtk17\">/&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">\t</span><span class=\"mtk17\">&lt;/</span><span class=\"mtk10\">PrivateRoute</span><span class=\"mtk17\">&gt;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">...</span></span></code></pre>\n<p>And now you should be able to access the <code>/</code> route or the Home page only when you're authenticated:</p>\n<p><img src=\"/9abde471077ac6c2b3ec3795169cafac/Home-Component.png\" alt=\"Home Component\"></p>\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>I hope I've shed some light on how to authenticate Svelte apps. You can do a lot from here, like adding <a href=\"https://kit.svelte.dev/\">Svelte Kit</a> to this project to simplify the routing system for your Svelte application.</p>\n<p>You can <a href=\"https://github.com/LoginRadius/engineering-blog-samples/tree/master/Svelte/SvelteAuthApp\">refer to the entire source code for this tutorial here</a>.</p>\n<p>You can also explore <a href=\"https://accounts.loginradius.com/auth.aspx?plan=developer&#x26;action=register\">LoginRadius</a> to add forgot password functionality or social signups with Facebook and Google.</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 .mtk11 { color: #DCDCAA; }\n  .dark-default-dark .mtk3 { color: #6A9955; }\n  .dark-default-dark .mtk12 { color: #9CDCFE; }\n  .dark-default-dark .mtk10 { color: #4EC9B0; }\n  .dark-default-dark .mtk6 { color: #D7BA7D; }\n  .dark-default-dark .mtk8 { color: #CE9178; }\n  .dark-default-dark .mtk7 { color: #B5CEA8; }\n  .dark-default-dark .mtk15 { color: #C586C0; }\n  .dark-default-dark .mtk4 { color: #569CD6; }\n  .dark-default-dark .mtk17 { color: #808080; }\n  .dark-default-dark .mtk14 { color: #F44747; }\n</style>","frontmatter":{"date":"March 10, 2022","updated_date":null,"description":"Are you building Svelte apps? In this tutorial, you'll learn to add secure user authentication in your Svelte apps using LoginRadius APIs.","title":"How to Authenticate Svelte Apps","tags":["Authentication","Svelte","LoginRadius"],"pinned":null,"coverImage":{"childImageSharp":{"fluid":{"aspectRatio":1.5037593984962405,"src":"/static/5d69922aea9b04a51e9dbc994fd914cd/ee604/authenticate-svelte-apps.png","srcSet":"/static/5d69922aea9b04a51e9dbc994fd914cd/69585/authenticate-svelte-apps.png 200w,\n/static/5d69922aea9b04a51e9dbc994fd914cd/497c6/authenticate-svelte-apps.png 400w,\n/static/5d69922aea9b04a51e9dbc994fd914cd/ee604/authenticate-svelte-apps.png 800w,\n/static/5d69922aea9b04a51e9dbc994fd914cd/f3583/authenticate-svelte-apps.png 1200w","sizes":"(max-width: 800px) 100vw, 800px"}}},"author":{"id":"Siddhant Varma","github":"FuzzySid","avatar":null}}}},{"node":{"excerpt":"Github is great, as you may already know. But, did you ever think to make your profile attractive for potential employers, followers…","fields":{"slug":"/engineering/build-your-github-profile/"},"html":"<p>Github is great, as you may already know.</p>\n<p>But, did you ever think to make your profile attractive for potential employers, followers, recruiters, and visitors?</p>\n<p>Let's make a better version of it.</p>\n<h2 id=\"github-profile-image-frame\" style=\"position:relative;\"><a href=\"#github-profile-image-frame\" aria-label=\"github profile image frame 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>Github Profile Image Frame</h2>\n<p>It's up to you to decide how you want this frame — photo-less, cartoon avatar, or best explaining image.</p>\n<p>For the best image, take a quality click; quality means not blurred, perfect lighting, and good posture.\nIf someone looks at the photo, it shall explain your personality.</p>\n<h2 id=\"github-profile-page\" style=\"position:relative;\"><a href=\"#github-profile-page\" aria-label=\"github profile 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>Github Profile Page</h2>\n<p>Github has a <a href=\"https://docs.github.com/en/account-and-profile/setting-up-and-managing-your-github-profile/customizing-your-profile/managing-your-profile-readme\">feature called README</a> if you do not know already.</p>\n<p>Check out some listing of <a href=\"https://github.com/abhisheknaiidu/awesome-github-profile-readme\">awesome GitHub profiles</a>.</p>\n<p>To start this, first, you need to create a project that is the same as your GitHub username.</p>\n<p><strong>Example:</strong> My user name is <code>abhir9</code>, and I need to create a repo with the same name <code>abhir9</code> with a <code>README.md</code> file.</p>\n<p>This <code>README.me</code> will act as the profile page: <a href=\"https://github.com/abhir9\">abhir9</a></p>\n<p>It is the actual README file created using a repo with my GitHub username: <a href=\"https://github.com/abhir9/abhir9/blob/main/README.md\">abhir9</a></p>\n<p>Here you can add your quotes, hello statement, greetings, etc. It is connected to the viewer on your behalf.</p>\n<p>So write a short paragraph or a brief story to introduce yourself.</p>\n<p>There are some apps from contributors that extract the information based on your profile name and share stats and charts.</p>\n<ul>\n<li><a href=\"https://github-readme-stats.vercel.app\">github readme stats</a>\ne.g.: <code>https://github-readme-stats.vercel.app/api?username=abhir9&#x26;show_icons=true&#x26;count_private=true&#x26;theme=react</code></li>\n<li><a href=\"https://readme-typing-svg.herokuapp.com\">readme typing svg</a>\ne.g.: <code>https://readme-typing-svg.herokuapp.com?size=50&#x26;center=true&#x26;vCenter=true&#x26;width=800&#x26;height=100&#x26;lines=Namaste%20%F0%9F%99%8F%3BPranam%20%F0%9F%99%8F%3BKhamma%20Ghani%20%F0%9F%99%8F%3BVanakkam%20%F0%9F%99%8F%3BSat%20Sri%20Akaal%20%F0%9F%99%8F%3BAssalam%20Alaikum%20%F0%9F%99%8F%3B</code></li>\n<li><a href=\"https://views.whatilearened.today\">whatilearened</a>\ne.g.: <code>https://views.whatilearened.today/views/github/abhir9/abhir9.svg?cache=remove</code></li>\n<li><a href=\"https://github-readme-streak-stats.herokuapp.com\">github readme streak stats</a>\ne.g.: <code>https://github-readme-streak-stats.herokuapp.com/?user=abhir9&#x26;theme=react</code></li>\n<li>SVG Icons\ne.g.: <code>https://raw.githubusercontent.com/devicons/devicon/master/icons/ubuntu/ubuntu-plain.svg</code></li>\n</ul>\n<p>Many other online apps can be used per your need — e.g., how you want to decorate your profile page.</p>\n<h2 id=\"github-pinned-repos\" style=\"position:relative;\"><a href=\"#github-pinned-repos\" aria-label=\"github pinned repos 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>Github Pinned Repos</h2>\n<p>Github allows you to pin up to 6 repos.</p>\n<p>Try to pin the best of your projects' repos. Mostly, people do visit these repos if they land on your profiles.</p>\n<h2 id=\"greeny-contributions\" style=\"position:relative;\"><a href=\"#greeny-contributions\" aria-label=\"greeny contributions 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>Greeny Contributions</h2>\n<p>There is a heat map that represents your contributions.</p>\n<p>Heat map graph will automatically generate as per your contributions. Try to keep it greener by contributing usefully to your favorite projects.</p>\n<h2 id=\"readme-for-every-project\" style=\"position:relative;\"><a href=\"#readme-for-every-project\" aria-label=\"readme for every 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>README for Every Project</h2>\n<p>Whether it's a minor or significant project, add a well-descriptive README file. It helps anyone clearly understand what your project does and how they can contribute if they want to.</p>\n<p>Format it in a better way; if you don't know very much about Markdown format, you can use an online tool like <a href=\"https://pandao.github.io/editor.md/en.html\">Pandao</a></p>\n<p>You can use images, screenshots, gifs, resources list, contribution guidelines, license, etc.</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":"February 28, 2022","updated_date":null,"description":"Your GitHub profile is vital in showcasing your programming skills. Learn how you can leverage GitHub profile to showcase your skills and expertise.","title":"How to Build Your Github Profile","tags":["Github"],"pinned":null,"coverImage":{"childImageSharp":{"fluid":{"aspectRatio":1.5037593984962405,"src":"/static/91552ab64061624f85043adb83cc0973/ee604/index.png","srcSet":"/static/91552ab64061624f85043adb83cc0973/69585/index.png 200w,\n/static/91552ab64061624f85043adb83cc0973/497c6/index.png 400w,\n/static/91552ab64061624f85043adb83cc0973/ee604/index.png 800w,\n/static/91552ab64061624f85043adb83cc0973/f3583/index.png 1200w","sizes":"(max-width: 800px) 100vw, 800px"}}},"author":{"id":"Abhimanyu Singh Rathore","github":"abhir9","avatar":null}}}},{"node":{"excerpt":"As human interactions become more and more digitalized, your business and personal websites have become far more important than a couple of…","fields":{"slug":"/engineering/importance-of-search-functionality-for-websites/"},"html":"<p>As human interactions become more and more digitalized, your business and personal websites have become far more important than a couple of decades ago.</p>\n<p>When a user lands on your website, it's essential to help the user find the right information as effectively as possible. Otherwise, the user may leave the website, losing potential business opportunities or visibility.</p>\n<p>One of the important ways to improve website design and help users find the information they want is to make the site searchable using the search functionality. It enables users to find content by searching for particular words without understanding or exploring the entire website or app, a quick or less complex way to find content.</p>\n<p>Let's discuss why your website needs to have search functionality and its benefits.</p>\n<h2 id=\"eliminate-site-navigation-hustle\" style=\"position:relative;\"><a href=\"#eliminate-site-navigation-hustle\" aria-label=\"eliminate site navigation hustle 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>Eliminate Site Navigation Hustle</h2>\n<p>If you have a large site -- assuming an e-commerce website or having hundreds of pages, users could find it extremely challenging to navigate to what they're looking for. In this situation, a search box allows your users to see what they need with a quick search.</p>\n<p>Regardless of where each user lands on your website, a search box will help them quickly find specific topics or pages.</p>\n<h2 id=\"improve-user-engagement-and-reduce-bounce-rate\" style=\"position:relative;\"><a href=\"#improve-user-engagement-and-reduce-bounce-rate\" aria-label=\"improve user engagement and reduce bounce rate 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>Improve User Engagement and Reduce Bounce Rate</h2>\n<p>Simply, the more straightforward it is for users to navigate around your entire website, the more probable that they will explore it.</p>\n<p>If it's difficult for users to track down what they're looking for, they'll head off to somewhere else that can fulfill their requirements. Help your users engage quite a bit on your site with a search textbox.</p>\n<h2 id=\"take-advantage-of-search-functionality\" style=\"position:relative;\"><a href=\"#take-advantage-of-search-functionality\" aria-label=\"take advantage of search functionality 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>Take Advantage of Search Functionality</h2>\n<p>Assuming you can incorporate your search bar into your Google Analytics, you'll have the option to track how frequently individuals look for a specific term. You can utilize this data for on-page content, order details, or billing plans.</p>\n<p>For example, if the most searched item on your website is <em>Perfume</em>, you could create a separate section or link on the home page so that users can directly navigate to that item faster.</p>\n<h2 id=\"mobile-users-prefer-search\" style=\"position:relative;\"><a href=\"#mobile-users-prefer-search\" aria-label=\"mobile users prefer search 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>Mobile Users Prefer Search</h2>\n<p>In this mobile era, it's critical to ensure your site and applications are mobile-friendly. Whenever users are on their mobile phones, they could be out and in a hurry, and a search feature will allow them to search and navigate to a specific page rapidly.</p>\n<h2 id=\"its-a-distinct-feature-users-expect\" style=\"position:relative;\"><a href=\"#its-a-distinct-feature-users-expect\" aria-label=\"its a distinct feature users expect 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>It's A Distinct Feature Users Expect</h2>\n<p>People are habitual to using some features to the level that they don't think much before using them. Search functionality is one of them. In this digital world, you can't have a site that doesn't offer an ideal user experience. Keep in mind that this minor component can significantly help increase your website’s engagement rates.</p>\n<h2 id=\"helps-improve-branding\" style=\"position:relative;\"><a href=\"#helps-improve-branding\" aria-label=\"helps improve branding 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>Helps Improve Branding</h2>\n<p>As the number of site visits increases, it indicates an improvement in brand engagement. Users visit your site because they are happy with the information and experience. This helps to raise your brand image among other competitors in your market.</p>\n<h2 id=\"reinforce-seo\" style=\"position:relative;\"><a href=\"#reinforce-seo\" aria-label=\"reinforce seo 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>Reinforce SEO</h2>\n<p>A positive user experience will lead to more visits to your site. As the visitors' count and time spent on your website increase, search engines like Google will consider your website performing well and of good quality, which will further elevate your page rankings in search results.</p>\n<p>You will also find some new keywords from users' searches to search for similar or different information on Google or other search engines. These search keywords can be those words that you want to target in SEO and other marketing and search strategies.</p>\n<h2 id=\"boosts-growth\" style=\"position:relative;\"><a href=\"#boosts-growth\" aria-label=\"boosts growth 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>Boosts Growth</h2>\n<p>As you expand your website with new content, blog posts, or new products, it can make your website cumbersome and affect user experience. Accordingly, finding an exact item can become difficult. However, with the right site search strategy, website size or navigation does not hamper the user experience. Users can find what they need and get ideas for other related items.</p>\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>In a nutshell, search functionality on your website helps offer a smooth, consistent experience for your users. And a well-implemented search functionality has more potential to ensure the website's success.</p>\n<p>Try not to stop your users from exploring all the features your site offers; add search functionality to your site soon!</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":"February 24, 2022","updated_date":null,"description":"Adding a search functionality is important for any website to improve user experience. Read more to understand the benefits of enabling search on your website.","title":"Why Implement Search Functionality for Your Websites","tags":["Search"],"pinned":null,"coverImage":{"childImageSharp":{"fluid":{"aspectRatio":1.5037593984962405,"src":"/static/3591f20e84a98d932a7c1fa348532e41/ee604/search-functionality.png","srcSet":"/static/3591f20e84a98d932a7c1fa348532e41/69585/search-functionality.png 200w,\n/static/3591f20e84a98d932a7c1fa348532e41/497c6/search-functionality.png 400w,\n/static/3591f20e84a98d932a7c1fa348532e41/ee604/search-functionality.png 800w,\n/static/3591f20e84a98d932a7c1fa348532e41/f3583/search-functionality.png 1200w","sizes":"(max-width: 800px) 100vw, 800px"}}},"author":{"id":"Neha Vyas","github":"nehavyasqa","avatar":null}}}},{"node":{"excerpt":"Introduction User authentication is the process of validating a user's identity to ensure that they are who they claim to be. Implementing…","fields":{"slug":"/engineering/guest-post/authenticating-flutter-apps/"},"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>User authentication is the process of validating a user's identity to ensure that they are who they claim to be. Implementing user authentication in your application is critical to prevent unauthorized users from accessing sensitive information.</p>\n<p>This tutorial focuses on implementing user authentication and registration in Flutter applications using the LoginRadius API.</p>\n<h2 id=\"prerequisites\" style=\"position:relative;\"><a href=\"#prerequisites\" aria-label=\"prerequisites 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>Prerequisites</h2>\n<p>If you wish to follow along with this tutorial, you must have the following set up:</p>\n<ul>\n<li><a href=\"https://accounts.loginradius.com/auth.aspx\">Sign up for a free LoginRadius developer account</a></li>\n<li>Any IDE that has <a href=\"https://docs.flutter.dev/get-started/install\">Flutter SDK</a> installed (i.e., <a href=\"https://developer.android.com/studio\">Android Studio</a>, <a href=\"https://code.visualstudio.com/\">VSCode</a>)</li>\n<li>A basic understanding of <a href=\"https://dart.dev/\">Dart</a> and <a href=\"https://flutter.dev/\">Flutter</a></li>\n</ul>\n<p>This tutorial is verified with Flutter v2.5.1 and Android Studio v3.5.</p>\n<h2 id=\"getting-started-with-loginradius\" style=\"position:relative;\"><a href=\"#getting-started-with-loginradius\" aria-label=\"getting started 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>Getting Started with LoginRadius</h2>\n<h3 id=\"what-is-loginradius\" style=\"position:relative;\"><a href=\"#what-is-loginradius\" aria-label=\"what is 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>What is LoginRadius?</h3>\n<p>LoginRadius is a cloud-based, SaaS Customer Identity and Access Management (CIAM) platform that provides developers and businesses simplified and robust features for managing customer identity, privacy, and access. LoginRadius offers high-level, secure, and well-documented APIs for integrating User Authentication and Single Sign-on (SSO) into your application.</p>\n<h3 id=\"why-use-loginradius\" style=\"position:relative;\"><a href=\"#why-use-loginradius\" aria-label=\"why use 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>Why use LoginRadius?</h3>\n<p>LoginRadius offers:</p>\n<ul>\n<li>A scalable infrastructure</li>\n<li>Built-in security measures to improve user account security and safe user data management</li>\n<li>Advanced login options such as Social SSO and Passwordless Login to improve the user experience</li>\n<li>SDKs and well-documented APIs for seamless integration into your application</li>\n</ul>\n<p>So, with everything out of the way, let's get started.</p>\n<h2 id=\"setting-up-loginradius-for-your-application\" style=\"position:relative;\"><a href=\"#setting-up-loginradius-for-your-application\" aria-label=\"setting up loginradius for your application 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>Setting Up LoginRadius for Your Application</h2>\n<p>After creating an account with LoginRadius, it sets up a free app for you. This is the app in which you would integrate the LoginRadius API with Flutter. Here my app name is “tayy”.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 768px; \"\n    >\n      <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 48.15384615384615%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAKCAYAAAC0VX7mAAAACXBIWXMAAAsTAAALEwEAmpwYAAABOElEQVQoz41S206EMBDlG/0c/8LE//DNHzAx8WXfNsYHN1lB2QVBoAVKWzjOcFkLi66TnKSdtmfOnKn39lmgEAK67SCUxW/Rdd0MeW1QawtZlvReQkgJpRS89CvD+0eILC+gjYHW2sGwN5RfErYto+VSPSzd2fsBPE42TUPQM7LmAiFGxJVBKDXKxuAQ+PD+ao+LDSrOW55yt5sDrh8CbCOJ7c4fFE7gC6wmy/MeFfkjyRtr7YlgWXiK1hpc3b3Ac6sNBxZxkuKYZLCUUnUN4xCuqeQVF7153P0QTsEHgqaeFwJlrVBV1ZnCGdm45qJH9pATliZWKHMi5G9g2Ts648m7Pq4Y3iuk1pDE0UDIUGZ4xI+FLGnKpifnKS+VudGOude0wmYfrbTsDIg/ak0e/ofwKZS4fw7xDUR5D2J55RUqAAAAAElFTkSuQmCC'); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"LoginRadius App Screen\"\n        title=\"LoginRadius App Screen\"\n        src=\"/static/33c5259fc16bb88fb1bb410700db0df3/e5715/app_window.png\"\n        srcset=\"/static/33c5259fc16bb88fb1bb410700db0df3/a6d36/app_window.png 650w,\n/static/33c5259fc16bb88fb1bb410700db0df3/e5715/app_window.png 768w,\n/static/33c5259fc16bb88fb1bb410700db0df3/ad00e/app_window.png 1366w\"\n        sizes=\"(max-width: 768px) 100vw, 768px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n      />\n    </span></p>\n<p>Next, you need to obtain your LoginRadius API credentials. To do so, login to your Dashboard and navigate to the <code>Configuration</code> tab in the sidebar menu. You will find your API credentials under the <code>API Key and Secret</code> section. Copy and store your <strong>APP Name</strong>, <strong>API Key</strong>, and <strong>API Secret</strong> somewhere safe and easily accessible.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 768px; \"\n    >\n      <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 48.15384615384615%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAKCAYAAAC0VX7mAAAACXBIWXMAAAsTAAALEwEAmpwYAAABuUlEQVQoz32SX2sTQRTFxzcJRWmVPtmCoERrq2kbH8TEtLUQxLd+t36F9q3xKXnyAyi0r1qCQtJgyJ/9k52dndmd3RzvTBKa0NALh91ZZn5z7tnLnpVO8KT4FexFGReN7zClEg2uNHSaIiOlS+SJGEIlCHmIURAg4BxSKbD14hes7VbBnn/AWa1ugUPHheN6UHFsD2udWvhMk28aiVGSkDSUitG+6YA9ffcZj7YqYBv7OP/WsMBefwjXH0FKiZigim5W9jmTssBZjUlpmqHbuSGHe1UCHoBtvieHE6CIIuvEbh6Pbw/S+zKZMl1cNVvksHCMx28MsIizqcP+gBx6HsJQkEIrTjIZGXfp3GUTkUNyfFK7Blt7e4SVV58WHHICxZSNmgIktWnWaZbd41Dj9GcbbHXnCKvbhxY4y3DgkDshwUUEGUk0HYGBvBvB/NpcGHou2MOXH5HLlxaA/aFLo8Dh+QE4jUPHlxBJtjRH069FZhq+64Dl8mWsvK4sAHsDBwG17QchBGX3143w21VLHWbT9R9P4rLVpwwLVazTYD+Ym8ORAUlFf3uSYWdEm3vRvcAf/0LUf3XxH7RzuT2/O2SbAAAAAElFTkSuQmCC'); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"LoginRadius Configuration Tab\"\n        title=\"LoginRadius Configuration Tab\"\n        src=\"/static/9ac569a072de64231421e73c6c7bb31c/e5715/configuration_tab.png\"\n        srcset=\"/static/9ac569a072de64231421e73c6c7bb31c/a6d36/configuration_tab.png 650w,\n/static/9ac569a072de64231421e73c6c7bb31c/e5715/configuration_tab.png 768w,\n/static/9ac569a072de64231421e73c6c7bb31c/ad00e/configuration_tab.png 1366w\"\n        sizes=\"(max-width: 768px) 100vw, 768px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n      />\n    </span></p>\n<h2 id=\"integrating-loginradius-api-with-your-flutter-application\" style=\"position:relative;\"><a href=\"#integrating-loginradius-api-with-your-flutter-application\" aria-label=\"integrating loginradius api with your flutter application 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>Integrating LoginRadius API with Your Flutter Application.</h2>\n<h3 id=\"step-1-create-a-new-flutter-project\" style=\"position:relative;\"><a href=\"#step-1-create-a-new-flutter-project\" aria-label=\"step 1 create a new flutter 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>Step 1: Create a New Flutter project</h3>\n<p>Create a new Flutter project and navigate to the folder of the application by running the following commands in your terminal:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"dart\" data-index=\"0\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">flutter create loginradius_example</span>\n<span class=\"grvsc-line\">cd loginradius_example</span></code></pre>\n<h3 id=\"step-2-install-dependencies\" style=\"position:relative;\"><a href=\"#step-2-install-dependencies\" aria-label=\"step 2 install dependencies 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: Install Dependencies</h3>\n<p>Next, you need to install the <code>dio</code> package as a dependency in our project. The <code>dio</code> package is a powerful HTTP client used for making network requests.</p>\n<p>Run the following command to get the newest version of the <code>dio</code> package in your project.</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"1\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">flutter pub add dio</span></code></pre>\n<p>Then, install the dependency by running <code>flutter pub get</code> in your terminal.</p>\n<h3 id=\"project-structure\" style=\"position:relative;\"><a href=\"#project-structure\" aria-label=\"project 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>Project Structure</h3>\n<p>The project is being structured in this order:</p>\n<p><img src=\"/b063fac3cc95c21f1d7327d989a883ef/folder-structure.png\" alt=\"Folder Structure\"></p>\n<ul>\n<li>Core (contains a class that handles network requests)</li>\n<li>Screens (the UI of our app)</li>\n<li>Utils (helper components)</li>\n</ul>\n<h3 id=\"step-3-setting-up-the-api-client-class\" style=\"position:relative;\"><a href=\"#step-3-setting-up-the-api-client-class\" aria-label=\"step 3 setting up the api client class 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: Setting up the API Client Class</h3>\n<p>Create a new dart file named <code>api_client.dart</code> and import the <code>dio</code> package into the file, as follows:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"dart\" data-index=\"2\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">import &#39;package:dio/dio.dart&#39;;</span></code></pre>\n<p>Now let’s create a class named <code>ApiClient</code> and initialize the <code>Dio</code> object in it. The <code>ApiClient</code> class will contain several methods for making network requests based on your features, including User Registration, User Login, Get User Profile Data, and User Logout.</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"dart\" data-index=\"3\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">import &#39;package:dio/dio.dart&#39;;</span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\">class ApiClient {</span>\n<span class=\"grvsc-line\">   final Dio _dio = Dio();</span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\">    Future&lt;Response&gt; registerUser() async {</span>\n<span class=\"grvsc-line\">        //IMPLEMENT USER REGISTRATION</span>\n<span class=\"grvsc-line\">    }</span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\">    Future&lt;Response&gt; login() async {</span>\n<span class=\"grvsc-line\">        //IMPLEMENT USER LOGIN</span>\n<span class=\"grvsc-line\">    }</span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\">    Future&lt;Response&gt; getUserProfileData() async {</span>\n<span class=\"grvsc-line\">        //GET USER PROFILE DATA</span>\n<span class=\"grvsc-line\">    }</span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\">    Future&lt;Response&gt; logout() async {</span>\n<span class=\"grvsc-line\">        //IMPLEMENT USER LOGOUT</span>\n<span class=\"grvsc-line\">     }</span>\n<span class=\"grvsc-line\">}</span></code></pre>\n<h3 id=\"step-4-implement-user-registration\" style=\"position:relative;\"><a href=\"#step-4-implement-user-registration\" aria-label=\"step 4 implement user registration 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: Implement User Registration</h3>\n<p>Before implementing the user registration functionality, you must first <a href=\"https://www.loginradius.com/developers/\">obtain the user registration endpoint URL from the LoginRadius API Docs</a>.</p>\n<p>After retrieving the endpoint URL, you need to send a POST request to the endpoint using the <code>Dio</code> package by passing in:</p>\n<ul>\n<li>the <code>apiKey</code> you obtained earlier as a query parameter;</li>\n<li>the <code>userData</code> as the request body; and,</li>\n<li>the <code>SOTT</code> key as a header, as shown below.</li>\n</ul>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"dart\" data-index=\"4\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">class ApiClient {</span>\n<span class=\"grvsc-line\">       //...</span>\n<span class=\"grvsc-line\">       Future&lt;Response&gt; registerUser(Map&lt;String, dynamic&gt;? userData) async {</span>\n<span class=\"grvsc-line\">        try {</span>\n<span class=\"grvsc-line\">          Response response = await _dio.post(</span>\n<span class=\"grvsc-line\">              &#39;https://api.loginradius.com/identity/v2/auth/register&#39;,  //ENDPONT URL</span>\n<span class=\"grvsc-line\">              data: userData, //REQUEST BODY</span>\n<span class=\"grvsc-line\">              queryParameters: {&#39;apikey&#39;: &#39;YOUR_API_KEY&#39;},  //QUERY PARAMETERS</span>\n<span class=\"grvsc-line\">              options: Options(headers: {&#39;X-LoginRadius-Sott&#39;: &#39;YOUR_SOTT_KEY&#39;, //HEADERS</span>\n<span class=\"grvsc-line\">          }));</span>\n<span class=\"grvsc-line\">          //returns the successful json object</span>\n<span class=\"grvsc-line\">          return response.data;</span>\n<span class=\"grvsc-line\">        } on DioError catch (e) {</span>\n<span class=\"grvsc-line\">          //returns the error object if there is</span>\n<span class=\"grvsc-line\">          return e.response!.data;</span>\n<span class=\"grvsc-line\">        }</span>\n<span class=\"grvsc-line\">      }</span>\n<span class=\"grvsc-line\">    }</span></code></pre>\n<h3 id=\"step-5-implement-user-login\" style=\"position:relative;\"><a href=\"#step-5-implement-user-login\" aria-label=\"step 5 implement user 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>Step 5: Implement User Login</h3>\n<p>The below code snippet shows how you’ll send a POST request to the LoginRadius login endpoint URL <code>https://api.loginradius.com/identity/v2/auth/login</code>, passing in your <code>apiKey</code> as a query parameter and the <code>email</code> and <code>password</code> of the user as the request body.</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"dart\" data-index=\"5\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">class ApiClient {</span>\n<span class=\"grvsc-line\">       //...</span>\n<span class=\"grvsc-line\">       Future&lt;Response&gt; login(String email, String password) async {</span>\n<span class=\"grvsc-line\">        try {</span>\n<span class=\"grvsc-line\">          Response response = await _dio.post(</span>\n<span class=\"grvsc-line\">            &#39;https://api.loginradius.com/identity/v2/auth/login&#39;,</span>\n<span class=\"grvsc-line\">            data: {</span>\n<span class=\"grvsc-line\">              &#39;email&#39;: email,</span>\n<span class=\"grvsc-line\">              &#39;password&#39;: password</span>\n<span class=\"grvsc-line\">            },</span>\n<span class=\"grvsc-line\">            queryParameters: {&#39;apikey&#39;: &#39;YOUR_API_KEY&#39;},</span>\n<span class=\"grvsc-line\">          );</span>\n<span class=\"grvsc-line\">          //returns the successful user data json object</span>\n<span class=\"grvsc-line\">          return response.data;</span>\n<span class=\"grvsc-line\">        } on DioError catch (e) {</span>\n<span class=\"grvsc-line\">          //returns the error object if any</span>\n<span class=\"grvsc-line\">          return e.response!.data;</span>\n<span class=\"grvsc-line\">        }</span>\n<span class=\"grvsc-line\">      }</span>\n<span class=\"grvsc-line\">    }</span></code></pre>\n<h3 id=\"step-6-get-user-profile-data\" style=\"position:relative;\"><a href=\"#step-6-get-user-profile-data\" aria-label=\"step 6 get user profile data 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 6: Get User Profile Data</h3>\n<p>To retrieve the user profile details, send a <code>GET</code> request to the Read Profile Endpoint URL <code>https://api.loginradius.com/identity/v2/auth/account</code>, passing in your <code>apiKey</code> as a query parameter and the user's access token as the header.</p>\n<blockquote>\n<p>The user’s access token is gotten from the successful response object of the User Login endpoint.</p>\n</blockquote>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"dart\" data-index=\"6\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">class ApiClient {</span>\n<span class=\"grvsc-line\">       //...</span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\">       Future&lt;Response&gt; getUserProfileData(String accesstoken) async {</span>\n<span class=\"grvsc-line\">        try {</span>\n<span class=\"grvsc-line\">          Response response = await _dio.get(</span>\n<span class=\"grvsc-line\">            &#39;https://api.loginradius.com/identity/v2/auth/account&#39;,</span>\n<span class=\"grvsc-line\">            queryParameters: {&#39;apikey&#39;: &#39;YOUR_API_KEY&#39;},</span>\n<span class=\"grvsc-line\">            options: Options(</span>\n<span class=\"grvsc-line\">              headers: {</span>\n<span class=\"grvsc-line\">                &#39;Authorization&#39;: &#39;Bearer ${YOUR_ACCESS_TOKEN}&#39;,</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 response.data;</span>\n<span class=\"grvsc-line\">        } on DioError catch (e) {</span>\n<span class=\"grvsc-line\">          return e.response!.data;</span>\n<span class=\"grvsc-line\">        }</span>\n<span class=\"grvsc-line\">    }</span></code></pre>\n<h3 id=\"step-7-implement-user-logout\" style=\"position:relative;\"><a href=\"#step-7-implement-user-logout\" aria-label=\"step 7 implement user logout 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 7: Implement User Logout</h3>\n<p>Finally, to implement the user logout functionality, you would send a <code>GET</code> request to the Invalidate User Access Token endpoint URL <code>https://api.loginradius.com/identity/v2/auth/access_token/InValidate</code>. This API call invalidates the user's active access token, requiring them to re-authenticate if they want to access their data.</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"dart\" data-index=\"7\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">class ApiClient {</span>\n<span class=\"grvsc-line\">       //...</span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\">      Future&lt;Response&gt; logout(String accessToken) async {</span>\n<span class=\"grvsc-line\">        try {</span>\n<span class=\"grvsc-line\">          Response response = await _dio.get(</span>\n<span class=\"grvsc-line\">            &#39;https://api.loginradius.com/identity/v2/auth/access_token/InValidate&#39;,</span>\n<span class=\"grvsc-line\">            queryParameters: {&#39;apikey&#39;: ApiSecret.apiKey},</span>\n<span class=\"grvsc-line\">            options: Options(</span>\n<span class=\"grvsc-line\">              headers: {&#39;Authorization&#39;: &#39;Bearer $accessToken&#39;},</span>\n<span class=\"grvsc-line\">            ),</span>\n<span class=\"grvsc-line\">          );</span>\n<span class=\"grvsc-line\">          return response.data;</span>\n<span class=\"grvsc-line\">        } on DioError catch (e) {</span>\n<span class=\"grvsc-line\">          return e.response!.data;</span>\n<span class=\"grvsc-line\">        }</span>\n<span class=\"grvsc-line\">      }</span>\n<span class=\"grvsc-line\">    }</span></code></pre>\n<p>That concludes the <code>ApiClient</code> class. Next, you'll build the UI for your Flutter application, making use of the methods you just created in the <code>ApiClient</code> class.</p>\n<h3 id=\"building-the-ui\" style=\"position:relative;\"><a href=\"#building-the-ui\" aria-label=\"building the ui 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>Building the UI</h3>\n<p>Your Flutter application will consist of four screens, which include:</p>\n<ul>\n<li>Registration Screen</li>\n<li>Login Screen</li>\n<li>Home Screen</li>\n</ul>\n<p>Let’s begin by building the Registration Screen.</p>\n<h3 id=\"registration-screen\" style=\"position:relative;\"><a href=\"#registration-screen\" aria-label=\"registration screen 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>Registration Screen</h3>\n<p>The <code>RegistrationScreen</code> has two <code>TextFormField</code> widgets that serve as our <code>email</code> and <code>password</code> fields, as well as an <code>ElevatedButton</code> to handle event submission, as shown in the code snippet below from the <code>register.dart</code> file.</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"dart\" data-index=\"8\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"> //...</span>\n<span class=\"grvsc-line\">    @override</span>\n<span class=\"grvsc-line\">    Widget build(BuildContext context) {</span>\n<span class=\"grvsc-line\">      Scaffold(</span>\n<span class=\"grvsc-line\">          backgroundColor: Colors.blueGrey[200],</span>\n<span class=\"grvsc-line\">          body: Form(</span>\n<span class=\"grvsc-line\">            key: _formKey,</span>\n<span class=\"grvsc-line\">            child: SizedBox(</span>\n<span class=\"grvsc-line\">              width: size.width,</span>\n<span class=\"grvsc-line\">              height: size.height,</span>\n<span class=\"grvsc-line\">              child: Align(</span>\n<span class=\"grvsc-line\">                alignment: Alignment.center,</span>\n<span class=\"grvsc-line\">                child: Container(</span>\n<span class=\"grvsc-line\">                  width: size.width * 0.85,</span>\n<span class=\"grvsc-line\">                  padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 30),</span>\n<span class=\"grvsc-line\">                  decoration: BoxDecoration(</span>\n<span class=\"grvsc-line\">                    color: Colors.white,</span>\n<span class=\"grvsc-line\">                    borderRadius: BorderRadius.circular(20),</span>\n<span class=\"grvsc-line\">                  ),</span>\n<span class=\"grvsc-line\">                  child: SingleChildScrollView(</span>\n<span class=\"grvsc-line\">                    child: Column(</span>\n<span class=\"grvsc-line\">                      crossAxisAlignment: CrossAxisAlignment.start,</span>\n<span class=\"grvsc-line\">                      children: &lt;Widget&gt;[</span>\n<span class=\"grvsc-line\">                        const Center(</span>\n<span class=\"grvsc-line\">                          child: Text(</span>\n<span class=\"grvsc-line\">                            &quot;Register&quot;,</span>\n<span class=\"grvsc-line\">                            style: TextStyle(</span>\n<span class=\"grvsc-line\">                              fontSize: 30,</span>\n<span class=\"grvsc-line\">                              fontWeight: FontWeight.bold,</span>\n<span class=\"grvsc-line\">                            ),</span>\n<span class=\"grvsc-line\">                          ),</span>\n<span class=\"grvsc-line\">                        ),</span>\n<span class=\"grvsc-line\">                        SizedBox(height: size.height * 0.05),</span>\n<span class=\"grvsc-line\">                        TextFormField(</span>\n<span class=\"grvsc-line\">                          validator: (value) =&gt;</span>\n<span class=\"grvsc-line\">                              Validator.validateEmail(value ?? &quot;&quot;),</span>\n<span class=\"grvsc-line\">                          controller: emailController,</span>\n<span class=\"grvsc-line\">                          keyboardType: TextInputType.emailAddress,</span>\n<span class=\"grvsc-line\">                          decoration: InputDecoration(</span>\n<span class=\"grvsc-line\">                            hintText: &quot;Email&quot;,</span>\n<span class=\"grvsc-line\">                            isDense: true,</span>\n<span class=\"grvsc-line\">                            border: OutlineInputBorder(</span>\n<span class=\"grvsc-line\">                              borderRadius: BorderRadius.circular(10),</span>\n<span class=\"grvsc-line\">                            ),</span>\n<span class=\"grvsc-line\">                          ),</span>\n<span class=\"grvsc-line\">                        ),</span>\n<span class=\"grvsc-line\">                        SizedBox(height: size.height * 0.03),</span>\n<span class=\"grvsc-line\">                        TextFormField(</span>\n<span class=\"grvsc-line\">                          obscureText: _showPassword,</span>\n<span class=\"grvsc-line\">                          validator: (value) =&gt;</span>\n<span class=\"grvsc-line\">                              Validator.validatePassword(value ?? &quot;&quot;),</span>\n<span class=\"grvsc-line\">                          controller: passwordController,</span>\n<span class=\"grvsc-line\">                          keyboardType: TextInputType.visiblePassword,</span>\n<span class=\"grvsc-line\">                          decoration: InputDecoration(</span>\n<span class=\"grvsc-line\">                            hintText: &quot;Password&quot;,</span>\n<span class=\"grvsc-line\">                            isDense: true,</span>\n<span class=\"grvsc-line\">                            border: OutlineInputBorder(</span>\n<span class=\"grvsc-line\">                              borderRadius: BorderRadius.circular(10),</span>\n<span class=\"grvsc-line\">                            ),</span>\n<span class=\"grvsc-line\">                          ),</span>\n<span class=\"grvsc-line\">                        ),</span>\n<span class=\"grvsc-line\">                        SizedBox(height: size.height * 0.06),</span>\n<span class=\"grvsc-line\">                        Row(</span>\n<span class=\"grvsc-line\">                          mainAxisAlignment: MainAxisAlignment.center,</span>\n<span class=\"grvsc-line\">                          children: [</span>\n<span class=\"grvsc-line\">                            Expanded(</span>\n<span class=\"grvsc-line\">                              child: ElevatedButton(</span>\n<span class=\"grvsc-line\">                                onPressed: _handleRegister,</span>\n<span class=\"grvsc-line\">                                style: ElevatedButton.styleFrom(</span>\n<span class=\"grvsc-line\">                                    primary: Colors.indigo,</span>\n<span class=\"grvsc-line\">                                    shape: RoundedRectangleBorder(</span>\n<span class=\"grvsc-line\">                                        borderRadius: BorderRadius.circular(10)),</span>\n<span class=\"grvsc-line\">                                    padding: const EdgeInsets.symmetric(</span>\n<span class=\"grvsc-line\">                                        horizontal: 40, vertical: 15)),</span>\n<span class=\"grvsc-line\">                                child: const Text(</span>\n<span class=\"grvsc-line\">                                  &quot;Register&quot;,</span>\n<span class=\"grvsc-line\">                                  style: TextStyle(</span>\n<span class=\"grvsc-line\">                                    fontSize: 20,</span>\n<span class=\"grvsc-line\">                                    fontWeight: FontWeight.bold,</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\">                      ],</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\">        );</span>\n<span class=\"grvsc-line\">    }</span>\n<span class=\"grvsc-line\">    //...</span></code></pre>\n<p>In the <code>onPressed</code> callback of the <code>ElevatedButton</code> widget, you'll handle the validation of your form data.</p>\n<p>If the form is validated, you pass your <code>userData</code> to the <code>registerUser</code> method from the <code>ApiClient</code> class for processing.</p>\n<p>If the response is an error, you show a snackbar with the error message. Otherwise, the user is redirected to the Login Screen.</p>\n<blockquote>\n<p>In the following example, you've provided only a few user attributes as <code>userData</code>. To view the complete list of user attributes, please look at the body parameters of the User Registration API here.</p>\n</blockquote>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"dart\" data-index=\"9\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">Future&lt;void&gt; _handleRegister() async {</span>\n<span class=\"grvsc-line\">    if (_formKey.currentState!.validate()) {</span>\n<span class=\"grvsc-line\">    //show snackbar to indicate loading</span>\n<span class=\"grvsc-line\">     ScaffoldMessenger.of(context).showSnackBar(SnackBar(</span>\n<span class=\"grvsc-line\">        content: const Text(&#39;Processing Data&#39;),</span>\n<span class=\"grvsc-line\">        backgroundColor: Colors.green.shade300,</span>\n<span class=\"grvsc-line\">      ));</span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\">   //the user data to be sent</span>\n<span class=\"grvsc-line\">    Map&lt;String, dynamic&gt; userData = {</span>\n<span class=\"grvsc-line\">      &quot;Email&quot;: [</span>\n<span class=\"grvsc-line\">        {</span>\n<span class=\"grvsc-line\">          &quot;Type&quot;: &quot;Primary&quot;,</span>\n<span class=\"grvsc-line\">          &quot;Value&quot;: emailController.text,</span>\n<span class=\"grvsc-line\">        }</span>\n<span class=\"grvsc-line\">      ],</span>\n<span class=\"grvsc-line\">      &quot;Password&quot;: passwordController.text,</span>\n<span class=\"grvsc-line\">      &quot;About&quot;: &#39;I am a new user :smile:&#39;,</span>\n<span class=\"grvsc-line\">      &quot;FirstName&quot;: &quot;Test&quot;,</span>\n<span class=\"grvsc-line\">      &quot;LastName&quot;: &quot;Account&quot;,</span>\n<span class=\"grvsc-line\">      &quot;BirthDate&quot;: &quot;10-12-1985&quot;,</span>\n<span class=\"grvsc-line\">      &quot;Gender&quot;: &quot;M&quot;,</span>\n<span class=\"grvsc-line\">    };</span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\">    //get response from ApiClient</span>\n<span class=\"grvsc-line\">    dynamic res = await _apiClient.registerUser(userData);</span>\n<span class=\"grvsc-line\">    ScaffoldMessenger.of(context).hideCurrentSnackBar();</span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\">    //checks if there is no error in the response body.</span>\n<span class=\"grvsc-line\">    //if error is not present, navigate the users to Login Screen.</span>\n<span class=\"grvsc-line\">    if (res[&#39;ErrorCode&#39;] == null) {</span>\n<span class=\"grvsc-line\">      Navigator.push(context,</span>\n<span class=\"grvsc-line\">          MaterialPageRoute(builder: (context) =&gt; const LoginScreen()));</span>\n<span class=\"grvsc-line\">    } else {</span>\n<span class=\"grvsc-line\">     //if error is present, display a snackbar showing the error messsage</span>\n<span class=\"grvsc-line\">      ScaffoldMessenger.of(context).showSnackBar(SnackBar(</span>\n<span class=\"grvsc-line\">        content: Text(&#39;Error: ${res[&#39;Message&#39;]}&#39;),</span>\n<span class=\"grvsc-line\">        backgroundColor: Colors.red.shade300,</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></code></pre>\n<h3 id=\"login-screen\" style=\"position:relative;\"><a href=\"#login-screen\" aria-label=\"login screen 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>Login Screen</h3>\n<p>The <code>LoginScreen</code> UI code is similar to the <code>RegistrationScreen</code> in that it also has two <code>TextFormField</code> widgets that serve as our <code>email</code> and <code>password</code> fields, as well as an <code>ElevatedButton</code> to handle event submission. So, for the sake of brevity, I’ll be leaving out the <code>LoginScreen</code> UI code and focusing mainly on the code to be written in the <code>ElevatedButton</code> onPressed callback in the <code>login_screen.dart</code> file.</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"dart\" data-index=\"10\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">//...</span>\n<span class=\"grvsc-line\">    //...</span>\n<span class=\"grvsc-line\">       Future&lt;void&gt; loginUsers() async {</span>\n<span class=\"grvsc-line\">        if (_formKey.currentState!.validate()) {</span>\n<span class=\"grvsc-line\">          //show snackbar to indicate loading</span>\n<span class=\"grvsc-line\">          ScaffoldMessenger.of(context).showSnackBar(SnackBar(</span>\n<span class=\"grvsc-line\">            content: const Text(&#39;Processing Data&#39;),</span>\n<span class=\"grvsc-line\">            backgroundColor: Colors.green.shade300,</span>\n<span class=\"grvsc-line\">          ));</span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\">          //get response from ApiClient</span>\n<span class=\"grvsc-line\">          dynamic res = await _apiClient.login(</span>\n<span class=\"grvsc-line\">            emailController.text,</span>\n<span class=\"grvsc-line\">            passwordController.text,</span>\n<span class=\"grvsc-line\">          );</span>\n<span class=\"grvsc-line\">          ScaffoldMessenger.of(context).hideCurrentSnackBar();</span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\">          //if there is no error, get the user&#39;s accesstoken and pass it to HomeScreen</span>\n<span class=\"grvsc-line\">          if (res[&#39;ErrorCode&#39;] == null) {</span>\n<span class=\"grvsc-line\">            String accessToken = res[&#39;access_token&#39;];</span>\n<span class=\"grvsc-line\">            Navigator.push(</span>\n<span class=\"grvsc-line\">                context,</span>\n<span class=\"grvsc-line\">                MaterialPageRoute(</span>\n<span class=\"grvsc-line\">                    builder: (context) =&gt; HomeScreen(accesstoken: accessToken)));</span>\n<span class=\"grvsc-line\">          } else {</span>\n<span class=\"grvsc-line\">          //if an error occurs, show snackbar with error message</span>\n<span class=\"grvsc-line\">          ScaffoldMessenger.of(context).showSnackBar(SnackBar(</span>\n<span class=\"grvsc-line\">            content: Text(&#39;Error: ${res[&#39;Message&#39;]}&#39;),</span>\n<span class=\"grvsc-line\">            backgroundColor: Colors.red.shade300,</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></code></pre>\n<p>The code snippet above is a method that first validates the form before passing the <code>email</code> and <code>password</code> values to the <code>login</code> method from the <code>ApiClient</code> class for handling.</p>\n<p>If the response is successful, you obtain the user’s <code>access_token</code> from the response data and pass it over to the <code>HomeScreen</code>. Otherwise, you display a snackbar with the error message that occurred.</p>\n<p>Then, you pass the <code>loginUsers</code> method you created above to the <code>onPressed</code> property of the <code>ElevatedButton</code> widget in the <code>LoginScreen</code>, as shown below.</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"dart\" data-index=\"11\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">    ElevatedButton(</span>\n<span class=\"grvsc-line\">        onPressed: loginUsers, //&lt;--</span>\n<span class=\"grvsc-line\">        style: ElevatedButton.styleFrom(</span>\n<span class=\"grvsc-line\">        primary: Colors.indigo,</span>\n<span class=\"grvsc-line\">        shape: RoundedRectangleBorder(</span>\n<span class=\"grvsc-line\">               borderRadius: BorderRadius.circular(10)),</span>\n<span class=\"grvsc-line\">               padding: const EdgeInsets.symmetric(</span>\n<span class=\"grvsc-line\">                        horizontal: 40, vertical: 15)),</span>\n<span class=\"grvsc-line\">        child: const Text(&quot;Login&quot;,</span>\n<span class=\"grvsc-line\">            style: TextStyle(</span>\n<span class=\"grvsc-line\">                fontSize: 20,</span>\n<span class=\"grvsc-line\">                fontWeight: FontWeight.bold,</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></code></pre>\n<p>Next, you need to provide a screen that reveals the user's profile data when they successfully log in, and the <code>HomeScreen</code> is there to do so.</p>\n<h3 id=\"home-screen\" style=\"position:relative;\"><a href=\"#home-screen\" aria-label=\"home screen 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>Home Screen</h3>\n<p>The <code>HomeScreen</code> displays the user’s profile details using a <code>FutureBuilder</code> widget that accepts a future <code>getUserData</code>.</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"dart\" data-index=\"12\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">      Future&lt;Map&lt;String, dynamic&gt;&gt; getUserData() async {</span>\n<span class=\"grvsc-line\">        dynamic userRes;</span>\n<span class=\"grvsc-line\">        userRes = await _apiClient.getUserProfileData(widget.accesstoken);</span>\n<span class=\"grvsc-line\">        return userRes;</span>\n<span class=\"grvsc-line\">      }</span></code></pre>\n<p>The <code>getUserData</code> method above is used to retrieve details of a user by passing in the <code>access_token</code> obtained earlier from the <code>LoginScreen</code> to the <code>ApiClient</code> <code>getUserProfileData</code> method.</p>\n<p>To display the result of your <code>getUserData</code> method on our screen, use a <code>FutureBuilder</code> widget. The code snippet below shows how to use the <code>FutureBuilder</code> to get the results of the <code>getUserData</code> future in the <code>home.dart</code> file.</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"dart\" data-index=\"13\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">    class HomeScreen extends StatefulWidget {</span>\n<span class=\"grvsc-line\">      final String accesstoken;</span>\n<span class=\"grvsc-line\">      const HomeScreen({Key? key, required this.accesstoken}) : super(key: key);</span>\n<span class=\"grvsc-line\">      @override</span>\n<span class=\"grvsc-line\">      State&lt;HomeScreen&gt; createState() =&gt; _HomeScreenState();</span>\n<span class=\"grvsc-line\">    }</span>\n<span class=\"grvsc-line\">    class _HomeScreenState extends State&lt;HomeScreen&gt; {</span>\n<span class=\"grvsc-line\">      //instance of ApiClient class</span>\n<span class=\"grvsc-line\">      final ApiClient _apiClient = ApiClient();</span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\">      //get user data from ApiClient</span>\n<span class=\"grvsc-line\">      Future&lt;Map&lt;String, dynamic&gt;&gt; getUserData() async {</span>\n<span class=\"grvsc-line\">        dynamic userRes;</span>\n<span class=\"grvsc-line\">        userRes = await _apiClient.getUserProfileData(widget.accesstoken);</span>\n<span class=\"grvsc-line\">        return userRes;</span>\n<span class=\"grvsc-line\">      }</span>\n<span class=\"grvsc-line\">      @override</span>\n<span class=\"grvsc-line\">      Widget build(BuildContext context) {</span>\n<span class=\"grvsc-line\">        var size = MediaQuery.of(context).size;</span>\n<span class=\"grvsc-line\">        return Scaffold(</span>\n<span class=\"grvsc-line\">          backgroundColor: Colors.white,</span>\n<span class=\"grvsc-line\">          body: SizedBox(</span>\n<span class=\"grvsc-line\">              width: size.width,</span>\n<span class=\"grvsc-line\">              height: size.height,</span>\n<span class=\"grvsc-line\">              child: FutureBuilder&lt;Map&lt;String, dynamic&gt;&gt;(</span>\n<span class=\"grvsc-line\">                future: getUserData(), //&lt;---</span>\n<span class=\"grvsc-line\">                builder: (context, snapshot) {</span>\n<span class=\"grvsc-line\">                  if (snapshot.hasData) {</span>\n<span class=\"grvsc-line\">                    if (snapshot.connectionState == ConnectionState.waiting) {</span>\n<span class=\"grvsc-line\">                      return Container(</span>\n<span class=\"grvsc-line\">                        height: size.height,</span>\n<span class=\"grvsc-line\">                        width: size.width,</span>\n<span class=\"grvsc-line\">                        color: Colors.blueGrey,</span>\n<span class=\"grvsc-line\">                        child: const Center(</span>\n<span class=\"grvsc-line\">                          child: CircularProgressIndicator(),</span>\n<span class=\"grvsc-line\">                        ),</span>\n<span class=\"grvsc-line\">                      );</span>\n<span class=\"grvsc-line\">                    }</span>\n<span class=\"grvsc-line\">                    //get results from snapshot</span>\n<span class=\"grvsc-line\">                    String fullName = snapshot.data![&#39;FullName&#39;];</span>\n<span class=\"grvsc-line\">                    String firstName = snapshot.data![&#39;FirstName&#39;];</span>\n<span class=\"grvsc-line\">                    String lastName = snapshot.data![&#39;LastName&#39;];</span>\n<span class=\"grvsc-line\">                    String birthDate = snapshot.data![&#39;BirthDate&#39;];</span>\n<span class=\"grvsc-line\">                    String email = snapshot.data![&#39;Email&#39;][0][&#39;Value&#39;];</span>\n<span class=\"grvsc-line\">                    String gender = snapshot.data![&#39;Gender&#39;];</span>\n<span class=\"grvsc-line\">                    return Container(</span>\n<span class=\"grvsc-line\">                      width: size.width,</span>\n<span class=\"grvsc-line\">                      height: size.height,</span>\n<span class=\"grvsc-line\">                      color: Colors.blueGrey.shade400,</span>\n<span class=\"grvsc-line\">                      child: SingleChildScrollView(</span>\n<span class=\"grvsc-line\">                        physics: const BouncingScrollPhysics(),</span>\n<span class=\"grvsc-line\">                     //...</span>\n<span class=\"grvsc-line\">                //...</span></code></pre>\n<p>Finally, let's add the logout feature.</p>\n<p>Add an <code>ElevatedButton</code> widget to the <code>HomeScreen</code>.</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"dart\" data-index=\"14\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">     TextButton(</span>\n<span class=\"grvsc-line\">        onPressed: (){},</span>\n<span class=\"grvsc-line\">        style: TextButton.styleFrom(</span>\n<span class=\"grvsc-line\">        backgroundColor: Colors.redAccent.shade700,</span>\n<span class=\"grvsc-line\">        shape: RoundedRectangleBorder(</span>\n<span class=\"grvsc-line\">               borderRadius: BorderRadius.circular(5)),</span>\n<span class=\"grvsc-line\">               padding: const EdgeInsets.symmetric(</span>\n<span class=\"grvsc-line\">                    vertical: 15, horizontal: 25)),</span>\n<span class=\"grvsc-line\">        child: const Text(&#39;Logout&#39;,</span>\n<span class=\"grvsc-line\">          style: TextStyle(color: Colors.white),           ),</span>\n<span class=\"grvsc-line\">        ),</span>\n<span class=\"grvsc-line\">     ),</span></code></pre>\n<p>On pressing the button, you'll call the <code>logout</code> method on the <code>ApiClient</code> class and pass in the <code>access_token</code> value, and then you route the user to the <code>LoginScreen</code>.</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"dart\" data-index=\"15\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">     TextButton(</span>\n<span class=\"grvsc-line\">        onPressed: () async {</span>\n<span class=\"grvsc-line\">          await _apiClient.logout(widget.accesstoken);</span>\n<span class=\"grvsc-line\">          Navigator.pushReplacement(</span>\n<span class=\"grvsc-line\">            context, MaterialPageRoute(builder: (context) =&gt; const LoginScreen()));</span>\n<span class=\"grvsc-line\">        },</span>\n<span class=\"grvsc-line\">        style: TextButton.styleFrom(</span>\n<span class=\"grvsc-line\">        backgroundColor: Colors.redAccent.shade700,</span>\n<span class=\"grvsc-line\">        shape: RoundedRectangleBorder(</span>\n<span class=\"grvsc-line\">               borderRadius: BorderRadius.circular(5)),</span>\n<span class=\"grvsc-line\">               padding: const EdgeInsets.symmetric(</span>\n<span class=\"grvsc-line\">                    vertical: 15, horizontal: 25)),</span>\n<span class=\"grvsc-line\">        child: const Text(&#39;Logout&#39;,</span>\n<span class=\"grvsc-line\">             style: TextStyle(color: Colors.white),</span>\n<span class=\"grvsc-line\">          ),</span>\n<span class=\"grvsc-line\">     ),</span></code></pre>\n<p><img src=\"/968d860d94a6f5f996e709e22dcec84a/demo-project.gif\" alt=\"Preview of demo project\"></p>\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>LoginRadius provides high-level, secure, and well-documented APIs to ease the implementation of authentication and user identity management. This tutorial has discussed LoginRadius's benefits and how to use the LoginRadius APIs to handle user authentication and registration in a Flutter application.</p>\n<p>The complete <a href=\"https://github.com/LoginRadius/engineering-blog-samples/tree/master/Flutter/Flutter_Auth_Guide\">source code of the demo application is available on GitHub</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</style>","frontmatter":{"date":"February 17, 2022","updated_date":null,"description":"Developing Flutter apps? Learn how to implement user authentication and registration in your Flutter applications quickly with LoginRadius APIs.","title":"Flutter Authentication: Implementing User Signup and Login","tags":["Authentication","Flutter","API"],"pinned":null,"coverImage":{"childImageSharp":{"fluid":{"aspectRatio":1.5037593984962405,"src":"/static/52db7c04cea4a2d8a1eab648a60d075d/ee604/user-authentication-for-flutter-apps.png","srcSet":"/static/52db7c04cea4a2d8a1eab648a60d075d/69585/user-authentication-for-flutter-apps.png 200w,\n/static/52db7c04cea4a2d8a1eab648a60d075d/497c6/user-authentication-for-flutter-apps.png 400w,\n/static/52db7c04cea4a2d8a1eab648a60d075d/ee604/user-authentication-for-flutter-apps.png 800w,\n/static/52db7c04cea4a2d8a1eab648a60d075d/f3583/user-authentication-for-flutter-apps.png 1200w","sizes":"(max-width: 800px) 100vw, 800px"}}},"author":{"id":"Yusuf Ahmed","github":null,"avatar":null}}}},{"node":{"excerpt":"Authentication and authorization are critical in every software application to secure user data and allow access to trusted users. In some…","fields":{"slug":"/engineering/guest-post/loopback-rest-api-authentication/"},"html":"<p>Authentication and authorization are critical in every software application to secure user data and allow access to trusted users. In some cases, implementing authentication and authorization is not an easy process.</p>\n<p>However, LoopBack 4 offers an authentication package <strong>@loopback/authentication</strong> that helps secure your application's API endpoints. It provides custom authentication strategies and a <strong>@authenticate</strong> decorator that requires minimal boilerplate code.</p>\n<h2 id=\"what-is-loopback\" style=\"position:relative;\"><a href=\"#what-is-loopback\" aria-label=\"what is loopback 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 LoopBack?</h2>\n<p>According to the <a href=\"https://loopback.io/doc/en/lb4/index.html\">LoopBack 4 documentation</a>:</p>\n<blockquote>\n<p>LoopBack is a flexible, open source Node.js and TypeScript framework built on Express. It helps you quickly develop APIs and microservices built on backend systems such as databases and SOAP or REST services.</p>\n</blockquote>\n<p>Loopback provides several features that allow you to build your application with less boilerplate code.</p>\n<h2 id=\"what-is-json-web-token-jwt\" style=\"position:relative;\"><a href=\"#what-is-json-web-token-jwt\" aria-label=\"what is json web token 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 JSON Web Token (JWT)?</h2>\n<p>JSON Web Token (JWT) is an open standard <a href=\"https://datatracker.ietf.org/doc/html/rfc7519.html\">defined by Internet Engineering Task Force (IETF) in RFC 7519</a>.</p>\n<p>It is a standard used for securely transferring claims between two parties over the internet. It uses JSON Web Signature (JWS) for the secure transfer of claims and eliminates the possibility of tampering. Accordingly, JWTs can be signed with either a secret (HMAC technique) or a public/private key pair (RSA or ECDSA).</p>\n<p>In simple words, it is used for authentication and secure information sharing. A JWT token is made up of three components that are separated by three dots:</p>\n<ul>\n<li><strong>Header:</strong> The header is made up of two parts — the kind of token, which is JWT; the signature technique used, either HMAC SHA256 or RSA.</li>\n<li><strong>Payload:</strong> The payload is the token, which includes the claims. Claims are assertions about an entity that provides extra information.</li>\n<li><strong>Signature:</strong> The encoded header, encoded payload, a secret, and the algorithm provided in the header comprise the signature.</li>\n</ul>\n<blockquote>\n<p>You can learn more about <a href=\"https://www.loginradius.com/blog/engineering/guest-post/jwt-authentication-best-practices-and-when-to-use/\">JWT and its best practices here</a>.</p>\n</blockquote>\n<h2 id=\"prerequisites\" style=\"position:relative;\"><a href=\"#prerequisites\" aria-label=\"prerequisites 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>Prerequisites</h2>\n<p>This tutorial is a hands-on demonstration. To follow along, be sure you have the following in place:</p>\n<ul>\n<li>A Linux machine — This tutorial will use Ubuntu 20.04.3 LTS (Focal Fossa). The tutorial also works well on other Linux distributions and operating systems.</li>\n<li><a href=\"https://nodejs.org/\"><strong>NodeJS</strong></a> — JavaScript runtime built on Chrome's V8 JavaScript engine.</li>\n<li><a href=\"https://www.mongodb.com/\"><strong>MongoDB</strong></a> — Document-oriented database program.</li>\n</ul>\n<h2 id=\"install-loopback-cli\" style=\"position:relative;\"><a href=\"#install-loopback-cli\" aria-label=\"install loopback cli 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>Install LoopBack CLI</h2>\n<p>To start building your LoopBack REST API, first install LoopBack CLI, which provides the quickest method to create a LoopBack 4 project that follows best practices.</p>\n<p>Use the command below to install the Loopback CLI globally:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"bash\" data-index=\"0\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk1\">npm i -g @loopback/cli</span></span></code></pre>\n<p>You can grab a cup of coffee while you wait for the installation to complete. Then open your command line, create an <code>AuthWithLooback</code> folder, and change the directory to the <code>AuthWithLooback</code> folder with commands below:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"bash\" data-index=\"1\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk1\">mkdir AuthWithLooback</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk11\">cd</span><span class=\"mtk1\"> AuthWithLooback</span></span></code></pre>\n<h2 id=\"scaffold-your-loopback-project\" style=\"position:relative;\"><a href=\"#scaffold-your-loopback-project\" aria-label=\"scaffold your loopback 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>Scaffold Your LoopBack Project</h2>\n<p>So, you've installed Loopback CLI and created a project directory. Let's run the following command to create a LoopBack project:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"bash\" data-index=\"2\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk1\">lb4 app</span></span></code></pre>\n<p>Select the options as in the following screenshot to complete the prompts.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 768px; \"\n    >\n      <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 19.076923076923077%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAECAYAAACOXx+WAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAzUlEQVQY022NW07DMBQFswyU2BFJHOM4SamUuu6LOg9o2f+GBlOqIiQ+RnN1jnRu4g47tG3QbYNpGqztHrRti418580/GGPoug7vPX3fMwwbkuEa2H4E1peAch7hFqR/J+8cWmtUUSCzDCmyXwvxsIhZlqY38jwnuVw/maeZEEbCOFG5PXJ75NkfSdeOJ23JSoUsK2R1d1H+cX7vSqVIXBzxYWI3zrjzyH5abt68BfpTYBUW7OGMeB0QdoWsX+JIHFb650FVx7tG1IYi+guBIXfDzP509gAAAABJRU5ErkJggg=='); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"Creating a loopback project\"\n        title=\"Creating a loopback project\"\n        src=\"/static/961eef175aa5895fad28c4f685080bb5/e5715/l5wg0nTQ.png\"\n        srcset=\"/static/961eef175aa5895fad28c4f685080bb5/a6d36/l5wg0nTQ.png 650w,\n/static/961eef175aa5895fad28c4f685080bb5/e5715/l5wg0nTQ.png 768w,\n/static/961eef175aa5895fad28c4f685080bb5/a2b88/l5wg0nTQ.png 908w\"\n        sizes=\"(max-width: 768px) 100vw, 768px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n      />\n    </span></p>\n<p>After completing the prompts, LoopBack will configure the TypeScript compiler and install all the required dependencies. Change directory to the <code>auth-with-loopback</code> folder.</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"bash\" data-index=\"3\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk11\">cd</span><span class=\"mtk1\"> auth-with-loopback</span></span></code></pre>\n<h2 id=\"create-a-model\" style=\"position:relative;\"><a href=\"#create-a-model\" aria-label=\"create a model 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>Create a Model</h2>\n<p>You've successfully created your Loopback application. Now, let’s create a Model to store the news details with the command below:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"bash\" data-index=\"4\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk1\">lb4 model</span></span></code></pre>\n<p>Select the options as in the following screenshot to complete the prompts.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 653px; \"\n    >\n      <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 88.3076923076923%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAASCAYAAABb0P4QAAAACXBIWXMAAAsTAAALEwEAmpwYAAAChUlEQVQ4y41U2XbaMBTkM4oXeQMvsmxL3nExhEAhJOny/z8zvXISkrQ9hYc52DIaz8wdebZYSbS/jhCnDXKCet7BW3WEM4LuhKAYwcQKfqqQ8gRFoeD7AWzbBmNsguM4E/TaLJMFfj494fG4w4/HIw53O9wfvmF/OmG3u8NuO2LYbpB2A7wkwSJgiCKfEBIiBEFAL/Dhed4Lochy5EWCtnNR1T6yXIDTxiJPUJYCaZqQshSlKsFFDCEsZJkJzkNCeiF6UzzLsow2CeS5gpQV6qqCXmvbEON6SWsRlssQhjGHZVkwLQbTZNO1xkfrk8IwidE0HWVT0G8NRYSikBBZActbwnM9suRdNjFmv4J9Inq7nsVFhu/f73E+7/H89IzN/oDhcEJaN/BImc1cmDb9+XWTbbNPZH9iFoQh2Vqg70uy2aGuK3wdVqibFqqUCEUEJ3AmQvui8D+ERZ5TuIJIFQ2hnPJTSlIEEkpybNYhhlU0Eb2ou0IYUbf6vicSRQpbNASdY0H3TiJIXUgd8y45XbUcUi32+z222y3ODw+QXQ8zr+B4Pgya6NywacLWJfyPA/gnYUKd09BT1pbTNKUuUgwJh+ALtI1D6+7tloUQ0MiJREqdm0RFGWpyQadIKk7P4qvK3i0LjgeyOo4jjscj2vWIuOkRiwxfgghz04Exty4TvprhIgonZRUNYhgGcJqyFXN66MBlFp1Vi4pt/VXgK7Xh05Q19H1HXayqmo5hjs0YYehD6qF1Ww8jHn+qTd11lJtCTqpZnBIyMF7Adj6W+0qG77U5Qa7WMHkOlwgMsj23XBi290J0C6H+psVxPJ0QnaX+dOnaJFSbJPHpg2HS5E04N9bmN2HVDEW2P4vTAAAAAElFTkSuQmCC'); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"Creating a News Model\"\n        title=\"Creating a News Model\"\n        src=\"/static/e7fbe76fba0c1221764e3040eaefaaea/e7dce/lSCGXHs.png\"\n        srcset=\"/static/e7fbe76fba0c1221764e3040eaefaaea/a6d36/lSCGXHs.png 650w,\n/static/e7fbe76fba0c1221764e3040eaefaaea/e7dce/lSCGXHs.png 653w\"\n        sizes=\"(max-width: 653px) 100vw, 653px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n      />\n    </span></p>\n<p>After the <code>date_created</code> property definition, press the enter key to exit the prompt.</p>\n<p>Loopback will create a <code>NewsModel</code> file in the <code>src/models</code> — the folder where <code>NewsModel</code> will be defined.</p>\n<p>Next, you need to create a data source to connect to your preferred database. For demonstration, this tutorial connects to a MongoDB database.</p>\n<p>Run the following command in your terminal to create a data source:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"bash\" data-index=\"5\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk1\">  lb4 datasource</span></span></code></pre>\n<p>Select the options as in the following screenshot to complete the prompts.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 768px; \"\n    >\n      <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 20.769230769230766%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAECAYAAACOXx+WAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAwUlEQVQY042N226EIBiEfQ9BaBTQddWiLFtN9pCmadL0/Z/nK5La615MZuY/zBTTFnl+f3L/+mB5fzLFN3wMmHDDvUbO04IbFkYfmMaRYRho2xbnXIYx5o+rqqIIl0C4bjh/4dT1ONvQtTVmP7ImaYc1ddp1+dFam7lLvvudHQU58Lqt3B4P6v5M3TRorVH6BaUUWmlkOiqFpCxLhBAZuz5w+J2llBSuPzGvkbhuLCEQYyQknucZ7z02tYsUvrf/Bz+HA3UVyNOrXQAAAABJRU5ErkJggg=='); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"Creating News datasource\"\n        title=\"Creating News datasource\"\n        src=\"/static/10614d56a1ce9b17d6271b3e6f8c1a48/e5715/pHvPgEQA.png\"\n        srcset=\"/static/10614d56a1ce9b17d6271b3e6f8c1a48/a6d36/pHvPgEQA.png 650w,\n/static/10614d56a1ce9b17d6271b3e6f8c1a48/e5715/pHvPgEQA.png 768w,\n/static/10614d56a1ce9b17d6271b3e6f8c1a48/59822/pHvPgEQA.png 916w\"\n        sizes=\"(max-width: 768px) 100vw, 768px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n      />\n    </span></p>\n<p>After completing the prompts, LoopBack will create the <code>News</code> file in the <code>src/datasource</code> folder.</p>\n<p>Then, create a <a href=\"https://loopback.io/doc/en/lb4/Repository.html\">Repository</a> for CRUD operations of your NewModel with the command below:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"bash\" data-index=\"6\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk1\">lb4 repository</span></span></code></pre>\n<p>After completing the prompts, LoopBack will create the <code>NewsModelRepository</code> file in the <code>src/repository</code> folder.</p>\n<p>Select <code>NewsDatasource</code> as the data source, <code>NewsModel</code> as the model for generating the repository, and <code>DefaultCrudRepository</code> as the base repository class.</p>\n<p>Your selection for the prompts shall look like the screenshot below.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 739px; \"\n    >\n      <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 18.923076923076923%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAECAYAAACOXx+WAAAACXBIWXMAAAsTAAALEwEAmpwYAAAA5UlEQVQY0z3PUW6CQBRGYbfRBJCZwhSYgSmCaIgCgkqV9MH9L+Z0amofTv63L/euPu8DxXzE3nq3B8r2QNV/o9ovRLsgmwuhPSCzGqF3vJs9Ks3IioLCFUURnucRBAG+77O6TGf6Y8ftemUaTpzHkfky0vUdp/NEP40MtzvL48G4LAzzjOlGwqIkFBIpBFLKJ/aLrt6qFGk1pa1odi2bzZZ6u6dpduTGkCYpprCkJkeqD0QUIxwSuKvC9Zr1X/9gbi2ZVtS17yDfgb57xcMY5cqJ4xidZSi3SsUYrdGuJEmeyKvXyz+323rKacyI+wAAAABJRU5ErkJggg=='); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"Creating News Repository\"\n        title=\"Creating News Repository\"\n        src=\"/static/1a34035e964d968e3ef9cd9abbe5dfec/f1d1f/WWH5tYJQ.png\"\n        srcset=\"/static/1a34035e964d968e3ef9cd9abbe5dfec/a6d36/WWH5tYJQ.png 650w,\n/static/1a34035e964d968e3ef9cd9abbe5dfec/f1d1f/WWH5tYJQ.png 739w\"\n        sizes=\"(max-width: 739px) 100vw, 739px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n      />\n    </span></p>\n<p>After completing the prompts, LoopBack will create the <code>NewsModelRepository</code> file in the <code>src/repository</code> folder.</p>\n<p>Lastly, create a controller for the <code>NewsModel</code> you created with the command below:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"bash\" data-index=\"7\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk1\">  lb4 controller</span></span></code></pre>\n<p>Your selection for the prompts should look like the screenshot below.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 768px; \"\n    >\n      <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 32.46153846153846%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAGCAYAAADDl76dAAAACXBIWXMAAAsTAAALEwEAmpwYAAABOUlEQVQY012Raa6bMBgAc4+wBLCJ2fJYA2EJkED7ev8DTb9Qqar6Y+RF1mhsn3wTUq4jxfNOPn1RP0vissItevxqxM9qPJ3gmxwVfWGuIXHkkwhanQl8DxUE+DI6jsNJhZqh62nrkr7N6Lucpr7RtS11VfDoWpqmYhoelPc7SVULGUGRoHIhy1DpjSCK/wiDq2b/+YNhGHm9dtb1zfSc+fX9zTQv9LKfVQ1RO2Cax4FOc846PrDci+Ae2Lb9EYbs+y4Fo4wb2/ZmWRaWdSWVcpPduGUpoYm4BApbKizHxRGBY51xRPKXT6F7uZA8W4q+47W8pXKTypeIN8ZxlCt3zPPMME0UlbytSK3QYOvrIf+fk+d5+LFBmYA09YhjDyPzOE7QWqOU4jjjyydodawdx5brWUfRv3UffgPXjrXaJGquKgAAAABJRU5ErkJggg=='); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"Creating News Controller\"\n        title=\"Creating News Controller\"\n        src=\"/static/ac16ed4650b5c64a8b2b367e9d5c07a9/e5715/iHD6lPCg.png\"\n        srcset=\"/static/ac16ed4650b5c64a8b2b367e9d5c07a9/a6d36/iHD6lPCg.png 650w,\n/static/ac16ed4650b5c64a8b2b367e9d5c07a9/e5715/iHD6lPCg.png 768w,\n/static/ac16ed4650b5c64a8b2b367e9d5c07a9/7fee5/iHD6lPCg.png 781w\"\n        sizes=\"(max-width: 768px) 100vw, 768px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n      />\n    </span></p>\n<p>After completing the prompts, LoopBack will create the <code>NewsController</code> file in the <code>src/controller</code> folder. So far, your project structure, omitting the <code>node_modules</code> folder, should look as follows.</p>\n<p>📦auth-with-loopback<br>\n┣ 📂public<br>\n┃ ┗ 📜index.html<br>\n┣ 📂src<br>\n┃ ┣ 📂<strong>tests</strong><br>\n┃ ┃ ┣ 📂acceptance<br>\n┃ ┃ ┃ ┣ 📜home-page.acceptance.ts<br>\n┃ ┃ ┃ ┣ 📜ping.controller.acceptance.ts<br>\n┃ ┃ ┃ ┗ 📜test-helper.ts<br>\n┃ ┃ ┗ 📜README.md<br>\n┃ ┣ 📂controllers<br>\n┃ ┃ ┣ 📜README.md<br>\n┃ ┃ ┣ 📜index.ts<br>\n┃ ┃ ┣ 📜news-controller.controller.ts<br>\n┃ ┃ ┗ 📜ping.controller.ts<br>\n┃ ┣ 📂datasources<br>\n┃ ┃ ┣ 📜README.md<br>\n┃ ┃ ┣ 📜index.ts<br>\n┃ ┃ ┗ 📜news.datasource.ts<br>\n┃ ┣ 📂models<br>\n┃ ┃ ┣ 📜README.md<br>\n┃ ┃ ┣ 📜index.ts<br>\n┃ ┃ ┗ 📜news-model.model.ts<br>\n┃ ┣ 📂repositories<br>\n┃ ┃ ┣ 📜README.md<br>\n┃ ┃ ┣ 📜index.ts<br>\n┃ ┃ ┗ 📜news-model.repository.ts<br>\n┃ ┣ 📜application.ts<br>\n┃ ┣ 📜index.ts<br>\n┃ ┣ 📜migrate.ts<br>\n┃ ┣ 📜openapi-spec.ts<br>\n┃ ┗ 📜sequence.ts<br>\n┣ 📜.dockerignore<br>\n┣ 📜.eslintignore<br>\n┣ 📜.eslintrc.js<br>\n┣ 📜.gitignore<br>\n┣ 📜.mocharc.json<br>\n┣ 📜.prettierignore<br>\n┣ 📜.prettierrc<br>\n┣ 📜.yo-rc.json<br>\n┣ 📜DEVELOPING.md<br>\n┣ 📜Dockerfile<br>\n┣ 📜README.md<br>\n┣ 📜package-lock.json<br>\n┣ 📜package.json<br>\n┗ 📜tsconfig.json</p>\n<h2 id=\"add-custom-data\" style=\"position:relative;\"><a href=\"#add-custom-data\" aria-label=\"add custom data 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>Add Custom Data</h2>\n<p>Now that you have the Model setup, run the server, and add some custom data to the News collection in MongoDB.</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"bash\" data-index=\"8\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk3\">#start the server</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    npm run start</span></span></code></pre>\n<p>The above command will start the TypeScript compiler, which will build the project and check for possible errors. If everything goes well with the code, you should see the output on the terminal, as follows:</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 626px; \"\n    >\n      <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 59.424920127795524%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAMCAYAAABiDJ37AAAACXBIWXMAAAsTAAALEwEAmpwYAAABcklEQVQoz5WT2U7DQAxF8xuQdbJnliSTpFkKSCD1Bf7/fy72qC20IAUejuxZfHXHcbxkUEiPPcTaQcwt8pcRRWeQ6QWlfXakZoOQE5JmdFFwNEdUjYZSEk3TII5jhGEIr1UGU2/R6xbzOFE+QNKFIhOoyxxNVSD0H8483sTA9+GfYbEoiuAlIoFIU0IgzTLwOqQDJnLEZ6I7fu45h8YYjOOIrutc3LYNy7JAa415ntG27Y+i34QuuZeSO0YIgYwc5nl+s+ZL/KQgCK6Fv4leBZVSmKYJfd/DWovD4YB1XZ0z3uPzsiwde2JOkJ0UReEKOLLDuq5RVZXLL2J/FuResUP+9FJK55L7yuLsjp//ryd/7xUXXQov+b3QrkNJLnqaQ60N7DBgof5N1EdNLq2lmaTzOKFRCs9fdAdPNRVUTT3KU7RafkF/AO/b1oDvRDTMUbCPZ55OYOT65hhe3zG+fUAfT4j0DNFtKMZn+M2Ax9ru8glh1VVqzANeXAAAAABJRU5ErkJggg=='); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"Starting LoopBack Server\"\n        title=\"Starting LoopBack Server\"\n        src=\"/static/41c93d10895b589fab75385876354cd5/af590/lSCGXHnw.png\"\n        srcset=\"/static/41c93d10895b589fab75385876354cd5/af590/lSCGXHnw.png 626w\"\n        sizes=\"(max-width: 626px) 100vw, 626px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n      />\n    </span></p>\n<p>Next, open your favorite browser and navigate to <code>http://localhost:3000</code>. You should see an output as follows:</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 538px; \"\n    >\n      <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 86.80297397769516%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAARCAYAAADdRIy+AAAACXBIWXMAAAsTAAALEwEAmpwYAAABcUlEQVQ4y51Ty07CQBRlqxv/wMR/08St8Xv8B6ONAUHZoEiMxk1faAmRPugbwSbUMj0OtIUGp03xJqdnenvn9Nw7mRrSiON4zVWRr8+ixhIkhDAFsnzGpYJ50arBqv/j8Hs6Reu2iUajDkEQ0arX0b5vo/vYRZPmbzgOD50Oek+9dB8pbzmcz6GpKmzbhuu60DUNY8OAoetQFAXqaATTNOF53v9a9ulGeyngeojCaPeWy+e4/EZSXjpbPdP3EodfEx8SL0KWZLzLMgYDBcE0gioAuhRDo7A+sz0JSgV/wnA1M0M3UtYRzEI4VMQaULEhPTy/gmBe1LYs9OU+JEGAyEtwHAsTA1CeY4w/8vUFM6wyx+REt1xVdVh01bJjYLljONwIEkKv2GIbNB/Fa6Ht+TEdFv25ag3DYbLWeEBqbyCmLNwBgb9LyyRZXxwD50fAyT5wepDw2SHlvUR0NZbFDg6HL8AbR3GVwzXwegnMnGKHv2idJp/NAdF7AAAAAElFTkSuQmCC'); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"LoopBack API Dashboard\"\n        title=\"LoopBack API Dashboard\"\n        src=\"/static/d25fb75f4d2128336023d21b10fb7445/9516f/hL9y8IIg.png\"\n        srcset=\"/static/d25fb75f4d2128336023d21b10fb7445/9516f/hL9y8IIg.png 538w\"\n        sizes=\"(max-width: 538px) 100vw, 538px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n      />\n    </span></p>\n<p>Now, click on the explorer link, where you can make requests to your LoopBack application. On the explorer page, locate the post endpoint and add some custom data to the news collection by clicking the <code>try it out</code> button with the data below on the request body.</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"json\" data-index=\"9\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk1\">{</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  </span><span class=\"mtk12\">&quot;title&quot;</span><span class=\"mtk1\">: </span><span class=\"mtk8\">&quot;Upgrade to Loopback V4&quot;</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  </span><span class=\"mtk12\">&quot;body&quot;</span><span class=\"mtk1\">: </span><span class=\"mtk8\">&quot;The developers of Loopback urges the V3 users to upgrade to V4 as soon as possible&quot;</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  </span><span class=\"mtk12\">&quot;date_created&quot;</span><span class=\"mtk1\">: </span><span class=\"mtk8\">&quot;2021-12-14T00:57:43.197Z&quot;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">}</span></span></code></pre>\n<p>Then, click the <code>execute</code> button to run the query.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 768px; \"\n    >\n      <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 44.30769230769231%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAJCAYAAAAywQxIAAAACXBIWXMAAAsTAAALEwEAmpwYAAABPElEQVQoz42R3UvDMBTF++8LOgXBd59FREEEX3z2wdc9DTe2sbZJ2qZJk/T2Y8e7bk7EgiP8OEnPuTeXNJqoD7yqGeZpjEWVISaDTV2ehlHYaIG1VVjsMBLRVKwxyxOUfY28cafTeuRlBq1S5K7EKheIbYEosRqiMtBdPVC0gQv8OPRDRg4F5z9liulijiU3Xuc84UprrGQ2sBQKsS6ReS7y4ajfe10TNNFeD6jKQRjLGQ/hHE9oDKTKkEiFREjEjLYWVfAoq2pQw0HrHahr0fTdL9ptjxY9OlbTNIgyCnwEGmzZ2ENsEodp2+31QM0NxwjMzrfEDWUIoLaDb9g40iHwt6OeSMpPExW9A9/Pq+YpaRT6x98ReM2J//Ldu8TZfYqrpxSTx79cMNfPAjcvYtiPZS659vwhxe2bxBd/9ai/3WkawwAAAABJRU5ErkJggg=='); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"Executing Queries\"\n        title=\"Executing Queries\"\n        src=\"/static/d5683b93fc29f01fa0fc14d19d2632a9/e5715/jiC_1P0A.png\"\n        srcset=\"/static/d5683b93fc29f01fa0fc14d19d2632a9/a6d36/jiC_1P0A.png 650w,\n/static/d5683b93fc29f01fa0fc14d19d2632a9/e5715/jiC_1P0A.png 768w,\n/static/d5683b93fc29f01fa0fc14d19d2632a9/60a1a/jiC_1P0A.png 1321w\"\n        sizes=\"(max-width: 768px) 100vw, 768px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n      />\n    </span></p>\n<p>You can add as many records as you like to experiment with the endpoints. The important thing to note here is that the endpoints are not protected. Anyone may create, read, update, and delete records.</p>\n<p>In a moment, this tutorial explains how to secure the endpoints so that only logged-in users can access them.</p>\n<p>To begin, install LoopBack <code>authentication</code> and <code>authentication-jwt</code>, as follows:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"bash\" data-index=\"10\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk1\">  npm i --save @loopback/authentication @loopback/authentication-jwt</span></span></code></pre>\n<h2 id=\"setup-authentication-components\" style=\"position:relative;\"><a href=\"#setup-authentication-components\" aria-label=\"setup authentication components 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>Setup Authentication Components</h2>\n<p>To protect the application, you'll implement user authentication and authorization, which implies that only logged-in users will be able to access your APIs. You'll create two endpoints in the User controller:</p>\n<ul>\n<li><code>/Signup</code> endpoint: To handle user’s sign up.</li>\n<li><code>/Login</code> endpoint: To handle user’s login.</li>\n</ul>\n<h3 id=\"create-your-signup-endpoint\" style=\"position:relative;\"><a href=\"#create-your-signup-endpoint\" aria-label=\"create your signup endpoint 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>Create Your Signup Endpoint</h3>\n<p>You’ll start with the signup controller to enable users to create an account. Create an empty controller with the command below:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"bash\" data-index=\"11\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk1\">    lb4 controller</span></span></code></pre>\n<p>Your selection for the prompts should be as follows:</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 744px; \"\n    >\n      <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 21.846153846153847%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAECAYAAACOXx+WAAAACXBIWXMAAAsTAAALEwEAmpwYAAAA1UlEQVQY002PW26DMBQF2UfAgG0wfvFwEgJEaqtK3f+Spg5qpH6Mztede07Rp8j955P0/WD+unH9OAj3J2rJuIT2V7RbUHam8wETEiGntxZjDG3bUlUVQoiTwgwDaVwYw0D0Xc6RGDxjDPnQnTmNkbTMxLHP4gFtPdI6RJNlZXmK3tKiURJ1LIRbYnvsHMfBtm3s+866rkzTTAgRmx/rznCRmlKqjKZqGkQWVX/tTqHWGh0dxim8fxFwzhFjPCdJKen7nq7rqOsaUV6yJLd6NXvL/k3+BUOWdTmOwgStAAAAAElFTkSuQmCC'); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"Creating User Controller\"\n        title=\"Creating User Controller\"\n        src=\"/static/fdd48a2c85636146145d0db2527f95f6/cab8c/6LCgT-Gw.png\"\n        srcset=\"/static/fdd48a2c85636146145d0db2527f95f6/a6d36/6LCgT-Gw.png 650w,\n/static/fdd48a2c85636146145d0db2527f95f6/cab8c/6LCgT-Gw.png 744w\"\n        sizes=\"(max-width: 744px) 100vw, 744px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n      />\n    </span></p>\n<p>Then, open the <code>src/controllers/user.controller.ts</code> file, and import the required modules with the following code snippet:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"javascript\" data-index=\"12\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk15\">import</span><span class=\"mtk1\"> { </span><span class=\"mtk12\">authenticate</span><span class=\"mtk1\">, </span><span class=\"mtk12\">TokenService</span><span class=\"mtk1\"> } </span><span class=\"mtk15\">from</span><span class=\"mtk1\"> </span><span class=\"mtk8\">&#39;@loopback/authentication&#39;</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk15\">import</span><span class=\"mtk1\"> {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">      </span><span class=\"mtk12\">Credentials</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">      </span><span class=\"mtk12\">MyUserService</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">      </span><span class=\"mtk12\">TokenServiceBindings</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">      </span><span class=\"mtk12\">User</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">      </span><span class=\"mtk12\">UserRepository</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">      </span><span class=\"mtk12\">UserServiceBindings</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    } </span><span class=\"mtk15\">from</span><span class=\"mtk1\"> </span><span class=\"mtk8\">&#39;@loopback/authentication-jwt&#39;</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk15\">import</span><span class=\"mtk1\"> { </span><span class=\"mtk12\">inject</span><span class=\"mtk1\"> } </span><span class=\"mtk15\">from</span><span class=\"mtk1\"> </span><span class=\"mtk8\">&#39;@loopback/core&#39;</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk15\">import</span><span class=\"mtk1\"> { </span><span class=\"mtk12\">model</span><span class=\"mtk1\">, </span><span class=\"mtk12\">property</span><span class=\"mtk1\">, </span><span class=\"mtk12\">repository</span><span class=\"mtk1\"> } </span><span class=\"mtk15\">from</span><span class=\"mtk1\"> </span><span class=\"mtk8\">&#39;@loopback/repository&#39;</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk15\">import</span><span class=\"mtk1\"> {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">      </span><span class=\"mtk12\">get</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">      </span><span class=\"mtk12\">getModelSchemaRef</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">      </span><span class=\"mtk12\">post</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">      </span><span class=\"mtk12\">requestBody</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">      </span><span class=\"mtk12\">SchemaObject</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    } </span><span class=\"mtk15\">from</span><span class=\"mtk1\"> </span><span class=\"mtk8\">&#39;@loopback/rest&#39;</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk15\">import</span><span class=\"mtk1\"> { </span><span class=\"mtk12\">SecurityBindings</span><span class=\"mtk1\">, </span><span class=\"mtk12\">securityId</span><span class=\"mtk1\">, </span><span class=\"mtk12\">UserProfile</span><span class=\"mtk1\"> } </span><span class=\"mtk15\">from</span><span class=\"mtk1\"> </span><span class=\"mtk8\">&#39;@loopback/security&#39;</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk15\">import</span><span class=\"mtk1\"> { </span><span class=\"mtk12\">genSalt</span><span class=\"mtk1\">, </span><span class=\"mtk12\">hash</span><span class=\"mtk1\"> } </span><span class=\"mtk15\">from</span><span class=\"mtk1\"> </span><span class=\"mtk8\">&#39;bcryptjs&#39;</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk15\">import</span><span class=\"mtk1\"> </span><span class=\"mtk12\">_</span><span class=\"mtk1\"> </span><span class=\"mtk15\">from</span><span class=\"mtk1\"> </span><span class=\"mtk8\">&#39;lodash&#39;</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    ........</span></span></code></pre>\n<p>Next, set up your user credential objects, and verify the user credentials using the <code>UserService</code>, injecting <code>MyUserService</code> into the <code>authentication-jwt</code> extension.</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"javascript\" data-index=\"13\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk1\">    @</span><span class=\"mtk11\">model</span><span class=\"mtk1\">()</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk15\">export</span><span class=\"mtk1\"> </span><span class=\"mtk4\">class</span><span class=\"mtk1\"> </span><span class=\"mtk10\">CreateUser</span><span class=\"mtk1\"> </span><span class=\"mtk4\">extends</span><span class=\"mtk1\"> </span><span class=\"mtk10\">User</span><span class=\"mtk1\"> {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">      @</span><span class=\"mtk11\">property</span><span class=\"mtk1\">({</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">        </span><span class=\"mtk12\">type:</span><span class=\"mtk1\"> </span><span class=\"mtk8\">&#39;string&#39;</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">        </span><span class=\"mtk12\">required:</span><span class=\"mtk1\"> </span><span class=\"mtk4\">true</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 class=\"mtk12\">password</span><span class=\"mtk1\">: </span><span class=\"mtk10\">string</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=\"mtk1\">    </span><span class=\"mtk4\">const</span><span class=\"mtk1\"> </span><span class=\"mtk12\">UserSchema</span><span class=\"mtk1\">: </span><span class=\"mtk10\">SchemaObject</span><span class=\"mtk1\"> = {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">      </span><span class=\"mtk12\">type:</span><span class=\"mtk1\"> </span><span class=\"mtk8\">&#39;object&#39;</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">      </span><span class=\"mtk12\">required:</span><span class=\"mtk1\"> [</span><span class=\"mtk8\">&#39;email&#39;</span><span class=\"mtk1\">, </span><span class=\"mtk8\">&#39;password&#39;</span><span class=\"mtk1\">],</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">      </span><span class=\"mtk12\">properties:</span><span class=\"mtk1\"> {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">        </span><span class=\"mtk12\">email:</span><span class=\"mtk1\"> {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">          </span><span class=\"mtk12\">type:</span><span class=\"mtk1\"> </span><span class=\"mtk8\">&#39;string&#39;</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">          </span><span class=\"mtk12\">format:</span><span class=\"mtk1\"> </span><span class=\"mtk8\">&#39;email&#39;</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 class=\"mtk12\">password:</span><span class=\"mtk1\"> {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">          </span><span class=\"mtk12\">type:</span><span class=\"mtk1\"> </span><span class=\"mtk8\">&#39;string&#39;</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">          </span><span class=\"mtk12\">minLength:</span><span class=\"mtk1\"> </span><span class=\"mtk7\">6</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 class=\"mtk1\">    };</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk15\">export</span><span class=\"mtk1\"> </span><span class=\"mtk4\">const</span><span class=\"mtk1\"> </span><span class=\"mtk12\">RequestBody</span><span class=\"mtk1\"> = {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">      </span><span class=\"mtk12\">description:</span><span class=\"mtk1\"> </span><span class=\"mtk8\">&#39;The input of login function&#39;</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">      </span><span class=\"mtk12\">required:</span><span class=\"mtk1\"> </span><span class=\"mtk4\">true</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">      </span><span class=\"mtk12\">content:</span><span class=\"mtk1\"> {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">        </span><span class=\"mtk8\">&#39;application/json&#39;</span><span class=\"mtk12\">:</span><span class=\"mtk1\"> { </span><span class=\"mtk12\">schema:</span><span class=\"mtk1\"> </span><span class=\"mtk12\">UserSchema</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=\"mtk1\">    </span><span class=\"mtk15\">export</span><span class=\"mtk1\"> </span><span class=\"mtk4\">class</span><span class=\"mtk1\"> </span><span class=\"mtk10\">UserController</span><span class=\"mtk1\"> {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">      </span><span class=\"mtk4\">constructor</span><span class=\"mtk1\">(</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">        @</span><span class=\"mtk11\">inject</span><span class=\"mtk1\">(</span><span class=\"mtk12\">TokenServiceBindings</span><span class=\"mtk1\">.</span><span class=\"mtk12\">TOKEN_SERVICE</span><span class=\"mtk1\">)</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">        </span><span class=\"mtk4\">public</span><span class=\"mtk1\"> </span><span class=\"mtk12\">jwtService</span><span class=\"mtk1\">: </span><span class=\"mtk10\">TokenService</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">        @</span><span class=\"mtk11\">inject</span><span class=\"mtk1\">(</span><span class=\"mtk12\">UserServiceBindings</span><span class=\"mtk1\">.</span><span class=\"mtk12\">USER_SERVICE</span><span class=\"mtk1\">)</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">        </span><span class=\"mtk4\">public</span><span class=\"mtk1\"> </span><span class=\"mtk12\">userService</span><span class=\"mtk1\">: </span><span class=\"mtk10\">MyUserService</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">        @</span><span class=\"mtk11\">inject</span><span class=\"mtk1\">(</span><span class=\"mtk12\">SecurityBindings</span><span class=\"mtk1\">.</span><span class=\"mtk12\">USER</span><span class=\"mtk1\">, { </span><span class=\"mtk12\">optional:</span><span class=\"mtk1\"> </span><span class=\"mtk4\">true</span><span class=\"mtk1\"> })</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">        </span><span class=\"mtk4\">public</span><span class=\"mtk1\"> </span><span class=\"mtk12\">user</span><span class=\"mtk1\">: </span><span class=\"mtk10\">UserProfile</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">        @</span><span class=\"mtk11\">repository</span><span class=\"mtk1\">(</span><span class=\"mtk12\">UserRepository</span><span class=\"mtk1\">) </span><span class=\"mtk4\">protected</span><span class=\"mtk1\"> </span><span class=\"mtk12\">userRepository</span><span class=\"mtk1\">: </span><span class=\"mtk10\">UserRepository</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>Finally, you'll build your signup endpoint, which will listen to POST requests. Here, you shall save the hashed version of the user's password in the database to keep it safe.</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"javascript\" data-index=\"14\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk1\">     @</span><span class=\"mtk11\">post</span><span class=\"mtk1\">(</span><span class=\"mtk8\">&#39;/signup&#39;</span><span class=\"mtk1\">, {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">      </span><span class=\"mtk12\">responses:</span><span class=\"mtk1\"> {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">        </span><span class=\"mtk8\">&#39;200&#39;</span><span class=\"mtk12\">:</span><span class=\"mtk1\"> {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">          </span><span class=\"mtk12\">description:</span><span class=\"mtk1\"> </span><span class=\"mtk8\">&#39;User&#39;</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">          </span><span class=\"mtk12\">content:</span><span class=\"mtk1\"> {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">            </span><span class=\"mtk8\">&#39;application/json&#39;</span><span class=\"mtk12\">:</span><span class=\"mtk1\"> {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">              </span><span class=\"mtk12\">schema:</span><span class=\"mtk1\"> {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">                </span><span class=\"mtk8\">&#39;x-ts-type&#39;</span><span class=\"mtk12\">:</span><span class=\"mtk1\"> </span><span class=\"mtk12\">User</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 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 class=\"mtk1\">    })</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk12\">async</span><span class=\"mtk1\"> </span><span class=\"mtk11\">signUp</span><span class=\"mtk1\">(</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">      @</span><span class=\"mtk11\">requestBody</span><span class=\"mtk1\">({</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">        </span><span class=\"mtk12\">content:</span><span class=\"mtk1\"> {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">          </span><span class=\"mtk8\">&#39;application/json&#39;</span><span class=\"mtk12\">:</span><span class=\"mtk1\"> {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">            </span><span class=\"mtk12\">schema:</span><span class=\"mtk1\"> </span><span class=\"mtk11\">getModelSchemaRef</span><span class=\"mtk1\">(</span><span class=\"mtk12\">CreateUser</span><span class=\"mtk1\">, {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">              </span><span class=\"mtk12\">title:</span><span class=\"mtk1\"> </span><span class=\"mtk8\">&#39;NewUser&#39;</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 class=\"mtk1\">        },</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">      })</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">      </span><span class=\"mtk12\">newUserRequest</span><span class=\"mtk1\">: </span><span class=\"mtk12\">CreateUser</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    ): </span><span class=\"mtk10\">Promise</span><span class=\"mtk1\">&lt;</span><span class=\"mtk12\">User</span><span class=\"mtk1\">&gt; {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">      const </span><span class=\"mtk12\">password</span><span class=\"mtk1\"> = </span><span class=\"mtk15\">await</span><span class=\"mtk1\"> </span><span class=\"mtk11\">hash</span><span class=\"mtk1\">(</span><span class=\"mtk12\">newUserRequest</span><span class=\"mtk1\">.</span><span class=\"mtk12\">password</span><span class=\"mtk1\">, </span><span class=\"mtk15\">await</span><span class=\"mtk1\"> </span><span class=\"mtk11\">genSalt</span><span class=\"mtk1\">());</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">      const </span><span class=\"mtk12\">savedUser</span><span class=\"mtk1\"> = </span><span class=\"mtk15\">await</span><span class=\"mtk1\"> </span><span class=\"mtk4\">this</span><span class=\"mtk1\">.</span><span class=\"mtk12\">userRepository</span><span class=\"mtk1\">.</span><span class=\"mtk11\">create</span><span class=\"mtk1\">(</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">        </span><span class=\"mtk12\">_</span><span class=\"mtk1\">.</span><span class=\"mtk11\">omit</span><span class=\"mtk1\">(</span><span class=\"mtk12\">newUserRequest</span><span class=\"mtk1\">, </span><span class=\"mtk8\">&#39;password&#39;</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=\"mtk1\">      await this.userRepository.userCredentials(savedUser.id).create({ </span><span class=\"mtk12\">password</span><span class=\"mtk1\"> });</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">      </span><span class=\"mtk15\">return</span><span class=\"mtk1\"> </span><span class=\"mtk12\">savedUser</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<h3 id=\"create-your-login-controller\" style=\"position:relative;\"><a href=\"#create-your-login-controller\" aria-label=\"create your login controller 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>Create Your Login Controller</h3>\n<p>Now that you've set up the signup endpoint, create the login endpoint so that registered users may log in to the API.</p>\n<p>Using the code snippet below, set up the login route in the <code>src/controllers/user.controller.ts</code> file. In the event of a successful log-in, a token is sent to the user.</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"javascript\" data-index=\"15\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk1\">      @</span><span class=\"mtk11\">post</span><span class=\"mtk1\">(</span><span class=\"mtk8\">&#39;/signin&#39;</span><span class=\"mtk1\">, {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">      </span><span class=\"mtk12\">responses:</span><span class=\"mtk1\"> {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">        </span><span class=\"mtk8\">&#39;200&#39;</span><span class=\"mtk12\">:</span><span class=\"mtk1\"> {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">          </span><span class=\"mtk12\">description:</span><span class=\"mtk1\"> </span><span class=\"mtk8\">&#39;Token&#39;</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">          </span><span class=\"mtk12\">content:</span><span class=\"mtk1\"> {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">            </span><span class=\"mtk8\">&#39;application/json&#39;</span><span class=\"mtk12\">:</span><span class=\"mtk1\"> {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">              </span><span class=\"mtk12\">schema:</span><span class=\"mtk1\"> {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">                </span><span class=\"mtk12\">type:</span><span class=\"mtk1\"> </span><span class=\"mtk8\">&#39;object&#39;</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">                </span><span class=\"mtk12\">properties:</span><span class=\"mtk1\"> {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">                  </span><span class=\"mtk12\">token:</span><span class=\"mtk1\"> {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">                    </span><span class=\"mtk12\">type:</span><span class=\"mtk1\"> </span><span class=\"mtk8\">&#39;string&#39;</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 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 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 class=\"mtk1\">    </span><span class=\"mtk12\">async</span><span class=\"mtk1\"> </span><span class=\"mtk11\">signIn</span><span class=\"mtk1\">(</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">      @</span><span class=\"mtk11\">requestBody</span><span class=\"mtk1\">(</span><span class=\"mtk12\">RequestBody</span><span class=\"mtk1\">) </span><span class=\"mtk12\">credentials</span><span class=\"mtk1\">: </span><span class=\"mtk12\">Credentials</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    ): </span><span class=\"mtk10\">Promise</span><span class=\"mtk1\">&lt;{ token: </span><span class=\"mtk12\">string</span><span class=\"mtk1\"> }&gt; {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">      const </span><span class=\"mtk12\">user</span><span class=\"mtk1\"> = </span><span class=\"mtk15\">await</span><span class=\"mtk1\"> </span><span class=\"mtk4\">this</span><span class=\"mtk1\">.</span><span class=\"mtk12\">userService</span><span class=\"mtk1\">.</span><span class=\"mtk11\">verifyCredentials</span><span class=\"mtk1\">(</span><span class=\"mtk12\">credentials</span><span class=\"mtk1\">);</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">      const </span><span class=\"mtk12\">userProfile</span><span class=\"mtk1\"> = </span><span class=\"mtk4\">this</span><span class=\"mtk1\">.</span><span class=\"mtk12\">userService</span><span class=\"mtk1\">.</span><span class=\"mtk11\">convertToUserProfile</span><span class=\"mtk1\">(</span><span class=\"mtk12\">user</span><span class=\"mtk1\">);</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">      const </span><span class=\"mtk12\">token</span><span class=\"mtk1\"> = </span><span class=\"mtk15\">await</span><span class=\"mtk1\"> </span><span class=\"mtk4\">this</span><span class=\"mtk1\">.</span><span class=\"mtk12\">jwtService</span><span class=\"mtk1\">.</span><span class=\"mtk11\">generateToken</span><span class=\"mtk1\">(</span><span class=\"mtk12\">userProfile</span><span class=\"mtk1\">);</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">      return { </span><span class=\"mtk12\">token</span><span class=\"mtk1\"> };</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    }</span></span></code></pre>\n<p>Perhaps, you can show the currently logged-in user by adding a <code>/whoami</code> endpoint.</p>\n<p>In the <code>src/controllers/user.controller.ts</code> file, get the details of the currently logged-in user using the code snippet below. Users should access this endpoint only when they are logged in.</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"javascript\" data-index=\"16\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk1\">      @</span><span class=\"mtk11\">authenticate</span><span class=\"mtk1\">(</span><span class=\"mtk8\">&#39;jwt&#39;</span><span class=\"mtk1\">)</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">      @</span><span class=\"mtk11\">get</span><span class=\"mtk1\">(</span><span class=\"mtk8\">&#39;/whoami&#39;</span><span class=\"mtk1\">, {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">        </span><span class=\"mtk12\">responses:</span><span class=\"mtk1\"> {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">          </span><span class=\"mtk8\">&#39;200&#39;</span><span class=\"mtk12\">:</span><span class=\"mtk1\"> {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">            </span><span class=\"mtk12\">description:</span><span class=\"mtk1\"> </span><span class=\"mtk8\">&#39;Return current user&#39;</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">            </span><span class=\"mtk12\">content:</span><span class=\"mtk1\"> {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">              </span><span class=\"mtk8\">&#39;application/json&#39;</span><span class=\"mtk12\">:</span><span class=\"mtk1\"> {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">                </span><span class=\"mtk12\">schema:</span><span class=\"mtk1\"> {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">                  </span><span class=\"mtk12\">type:</span><span class=\"mtk1\"> </span><span class=\"mtk8\">&#39;string&#39;</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 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 class=\"mtk1\">      })</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">      </span><span class=\"mtk12\">async</span><span class=\"mtk1\"> </span><span class=\"mtk11\">whoAmI</span><span class=\"mtk1\">(</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">        @</span><span class=\"mtk11\">inject</span><span class=\"mtk1\">(</span><span class=\"mtk12\">SecurityBindings</span><span class=\"mtk1\">.</span><span class=\"mtk12\">USER</span><span class=\"mtk1\">)</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">        </span><span class=\"mtk12\">loggedInUserProfile</span><span class=\"mtk1\">: </span><span class=\"mtk12\">UserProfile</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">      ): </span><span class=\"mtk10\">Promise</span><span class=\"mtk1\">&lt;</span><span class=\"mtk12\">string</span><span class=\"mtk1\">&gt; {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">        return loggedInUserProfile</span><span class=\"mtk12\">[securityId];</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk12\">      }</span></span></code></pre>\n<p>Now, open <code>src/application.ts</code> and bind the authentication components to your application class. First, import Loopback <code>AuthenticationComponent</code>, <code>JWTAuthenticationComponent</code>, and <code>NewsDataSource</code> from your <code>datasources</code> using the following code snippet:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"javascript\" data-index=\"17\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk3\">//...</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk15\">import</span><span class=\"mtk1\"> { </span><span class=\"mtk12\">AuthenticationComponent</span><span class=\"mtk1\"> } </span><span class=\"mtk15\">from</span><span class=\"mtk1\"> </span><span class=\"mtk8\">&quot;@loopback/authentication&quot;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk15\">import</span><span class=\"mtk1\"> {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  </span><span class=\"mtk12\">JWTAuthenticationComponent</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">  </span><span class=\"mtk12\">UserServiceBindings</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">} </span><span class=\"mtk15\">from</span><span class=\"mtk1\"> </span><span class=\"mtk8\">&quot;@loopback/authentication-jwt&quot;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk15\">import</span><span class=\"mtk1\"> { </span><span class=\"mtk12\">NewsDataSource</span><span class=\"mtk1\"> } </span><span class=\"mtk15\">from</span><span class=\"mtk1\"> </span><span class=\"mtk8\">&quot;./datasources&quot;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk3\">//...</span></span></code></pre>\n<p>Then, mount the jwt authentication system and bind your <code>NewsDataSource</code> to the <code>UserService</code> data source.</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"javascript\" data-index=\"18\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk3\">//...</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk3\">// ------ ADD SNIPPET INSIDE THE CONTRUCTOR BLOCK ---------</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk4\">this</span><span class=\"mtk1\">.</span><span class=\"mtk11\">component</span><span class=\"mtk1\">(</span><span class=\"mtk12\">AuthenticationComponent</span><span class=\"mtk1\">)</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk4\">this</span><span class=\"mtk1\">.</span><span class=\"mtk11\">component</span><span class=\"mtk1\">(</span><span class=\"mtk12\">JWTAuthenticationComponent</span><span class=\"mtk1\">)</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk4\">this</span><span class=\"mtk1\">.</span><span class=\"mtk11\">dataSource</span><span class=\"mtk1\">(</span><span class=\"mtk12\">NewsDataSource</span><span class=\"mtk1\">, </span><span class=\"mtk12\">UserServiceBindings</span><span class=\"mtk1\">.</span><span class=\"mtk12\">DATASOURCE_NAME</span><span class=\"mtk1\">)</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk3\">//...</span></span></code></pre>\n<p>Finally, add the authenticate action in the Sequence. Also, modify the error when authentication fails to return status code 401 (Unauthorized). Open the <code>src/sequence.ts</code> file and add the code snippet below:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"javascript\" data-index=\"19\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk15\">import</span><span class=\"mtk1\"> { </span><span class=\"mtk12\">FindRoute</span><span class=\"mtk1\">, </span><span class=\"mtk12\">InvokeMethod</span><span class=\"mtk1\">, </span><span class=\"mtk12\">MiddlewareSequence</span><span class=\"mtk1\">, </span><span class=\"mtk12\">ParseParams</span><span class=\"mtk1\">, </span><span class=\"mtk12\">Reject</span><span class=\"mtk1\">, </span><span class=\"mtk12\">RequestContext</span><span class=\"mtk1\">, </span><span class=\"mtk12\">Send</span><span class=\"mtk1\">, </span><span class=\"mtk12\">SequenceActions</span><span class=\"mtk1\">, </span><span class=\"mtk12\">SequenceHandler</span><span class=\"mtk1\"> } </span><span class=\"mtk15\">from</span><span class=\"mtk1\"> </span><span class=\"mtk8\">&#39;@loopback/rest&#39;</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk15\">import</span><span class=\"mtk1\"> {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">        </span><span class=\"mtk12\">AuthenticateFn</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">        </span><span class=\"mtk12\">AuthenticationBindings</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">        </span><span class=\"mtk12\">AUTHENTICATION_STRATEGY_NOT_FOUND</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">        </span><span class=\"mtk12\">USER_PROFILE_NOT_FOUND</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    } </span><span class=\"mtk15\">from</span><span class=\"mtk1\"> </span><span class=\"mtk8\">&#39;@loopback/authentication&#39;</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk15\">import</span><span class=\"mtk1\"> { </span><span class=\"mtk12\">inject</span><span class=\"mtk1\"> } </span><span class=\"mtk15\">from</span><span class=\"mtk1\"> </span><span class=\"mtk8\">&quot;@loopback/core&quot;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk15\">export</span><span class=\"mtk1\"> </span><span class=\"mtk4\">class</span><span class=\"mtk1\"> </span><span class=\"mtk10\">MySequence</span><span class=\"mtk1\"> </span><span class=\"mtk4\">implements</span><span class=\"mtk1\"> </span><span class=\"mtk10\">SequenceHandler</span><span class=\"mtk1\"> {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">        </span><span class=\"mtk4\">constructor</span><span class=\"mtk1\">(</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">            @</span><span class=\"mtk11\">inject</span><span class=\"mtk1\">(</span><span class=\"mtk12\">SequenceActions</span><span class=\"mtk1\">.</span><span class=\"mtk12\">FIND_ROUTE</span><span class=\"mtk1\">) </span><span class=\"mtk4\">protected</span><span class=\"mtk1\"> </span><span class=\"mtk12\">findRoute</span><span class=\"mtk1\">: </span><span class=\"mtk10\">FindRoute</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">            @</span><span class=\"mtk11\">inject</span><span class=\"mtk1\">(</span><span class=\"mtk12\">SequenceActions</span><span class=\"mtk1\">.</span><span class=\"mtk12\">PARSE_PARAMS</span><span class=\"mtk1\">)</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">            </span><span class=\"mtk4\">protected</span><span class=\"mtk1\"> </span><span class=\"mtk12\">parseParams</span><span class=\"mtk1\">: </span><span class=\"mtk10\">ParseParams</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">            @</span><span class=\"mtk11\">inject</span><span class=\"mtk1\">(</span><span class=\"mtk12\">SequenceActions</span><span class=\"mtk1\">.</span><span class=\"mtk12\">INVOKE_METHOD</span><span class=\"mtk1\">) </span><span class=\"mtk4\">protected</span><span class=\"mtk1\"> </span><span class=\"mtk12\">invoke</span><span class=\"mtk1\">: </span><span class=\"mtk10\">InvokeMethod</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">            @</span><span class=\"mtk11\">inject</span><span class=\"mtk1\">(</span><span class=\"mtk12\">SequenceActions</span><span class=\"mtk1\">.</span><span class=\"mtk12\">SEND</span><span class=\"mtk1\">) </span><span class=\"mtk4\">protected</span><span class=\"mtk1\"> </span><span class=\"mtk12\">send</span><span class=\"mtk1\">: </span><span class=\"mtk10\">Send</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">            @</span><span class=\"mtk11\">inject</span><span class=\"mtk1\">(</span><span class=\"mtk12\">SequenceActions</span><span class=\"mtk1\">.</span><span class=\"mtk12\">REJECT</span><span class=\"mtk1\">) </span><span class=\"mtk4\">protected</span><span class=\"mtk1\"> </span><span class=\"mtk12\">reject</span><span class=\"mtk1\">: </span><span class=\"mtk10\">Reject</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">            @</span><span class=\"mtk11\">inject</span><span class=\"mtk1\">(</span><span class=\"mtk12\">AuthenticationBindings</span><span class=\"mtk1\">.</span><span class=\"mtk12\">AUTH_ACTION</span><span class=\"mtk1\">)</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">            </span><span class=\"mtk4\">protected</span><span class=\"mtk1\"> </span><span class=\"mtk12\">authenticateRequest</span><span class=\"mtk1\">: </span><span class=\"mtk10\">AuthenticateFn</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 class=\"mtk4\">async</span><span class=\"mtk1\"> </span><span class=\"mtk11\">handle</span><span class=\"mtk1\">(</span><span class=\"mtk12\">context</span><span class=\"mtk1\">: </span><span class=\"mtk10\">RequestContext</span><span class=\"mtk1\">) {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">            </span><span class=\"mtk15\">try</span><span class=\"mtk1\"> {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">                </span><span class=\"mtk4\">const</span><span class=\"mtk1\"> { </span><span class=\"mtk12\">request</span><span class=\"mtk1\">, </span><span class=\"mtk12\">response</span><span class=\"mtk1\"> } = </span><span class=\"mtk12\">context</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">                </span><span class=\"mtk4\">const</span><span class=\"mtk1\"> </span><span class=\"mtk12\">route</span><span class=\"mtk1\"> = </span><span class=\"mtk4\">this</span><span class=\"mtk1\">.</span><span class=\"mtk11\">findRoute</span><span class=\"mtk1\">(</span><span class=\"mtk12\">request</span><span class=\"mtk1\">);</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">                </span><span class=\"mtk3\">//call authentication action</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">                </span><span class=\"mtk15\">await</span><span class=\"mtk1\"> </span><span class=\"mtk4\">this</span><span class=\"mtk1\">.</span><span class=\"mtk11\">authenticateRequest</span><span class=\"mtk1\">(</span><span class=\"mtk12\">request</span><span class=\"mtk1\">);</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">                </span><span class=\"mtk3\">// Authentication successful, proceed to invoke controller</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">                </span><span class=\"mtk4\">const</span><span class=\"mtk1\"> </span><span class=\"mtk12\">args</span><span class=\"mtk1\"> = </span><span class=\"mtk15\">await</span><span class=\"mtk1\"> </span><span class=\"mtk4\">this</span><span class=\"mtk1\">.</span><span class=\"mtk11\">parseParams</span><span class=\"mtk1\">(</span><span class=\"mtk12\">request</span><span class=\"mtk1\">, </span><span class=\"mtk12\">route</span><span class=\"mtk1\">);</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">                </span><span class=\"mtk4\">const</span><span class=\"mtk1\"> </span><span class=\"mtk12\">result</span><span class=\"mtk1\"> = </span><span class=\"mtk15\">await</span><span class=\"mtk1\"> </span><span class=\"mtk4\">this</span><span class=\"mtk1\">.</span><span class=\"mtk11\">invoke</span><span class=\"mtk1\">(</span><span class=\"mtk12\">route</span><span class=\"mtk1\">, </span><span class=\"mtk12\">args</span><span class=\"mtk1\">);</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">                </span><span class=\"mtk4\">this</span><span class=\"mtk1\">.</span><span class=\"mtk11\">send</span><span class=\"mtk1\">(</span><span class=\"mtk12\">response</span><span class=\"mtk1\">, </span><span class=\"mtk12\">result</span><span class=\"mtk1\">);</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">            } </span><span class=\"mtk15\">catch</span><span class=\"mtk1\"> (</span><span class=\"mtk12\">error</span><span class=\"mtk1\">) {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">                </span><span class=\"mtk15\">if</span><span class=\"mtk1\"> (</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">                    </span><span class=\"mtk12\">error</span><span class=\"mtk1\">.</span><span class=\"mtk12\">code</span><span class=\"mtk1\"> === </span><span class=\"mtk12\">AUTHENTICATION_STRATEGY_NOT_FOUND</span><span class=\"mtk1\"> ||</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">                    </span><span class=\"mtk12\">error</span><span class=\"mtk1\">.</span><span class=\"mtk12\">code</span><span class=\"mtk1\"> === </span><span class=\"mtk12\">USER_PROFILE_NOT_FOUND</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">                ) {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">                    </span><span class=\"mtk10\">Object</span><span class=\"mtk1\">.</span><span class=\"mtk11\">assign</span><span class=\"mtk1\">(</span><span class=\"mtk12\">error</span><span class=\"mtk1\">, { </span><span class=\"mtk12\">statusCode:</span><span class=\"mtk1\"> </span><span class=\"mtk7\">401</span><span class=\"mtk3\">/* Unauthorized */</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 class=\"mtk4\">this</span><span class=\"mtk1\">.</span><span class=\"mtk11\">reject</span><span class=\"mtk1\">(</span><span class=\"mtk12\">context</span><span class=\"mtk1\">, </span><span class=\"mtk12\">error</span><span class=\"mtk1\">);</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">                </span><span class=\"mtk15\">return</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 class=\"mtk1\">    }</span></span></code></pre>\n<h2 id=\"protect-news-endpoints\" style=\"position:relative;\"><a href=\"#protect-news-endpoints\" aria-label=\"protect news endpoints 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>Protect News Endpoints</h2>\n<p>So far, you've implemented user authentication for your API. Now, protect your News endpoints so that only authenticated users can access those routes.</p>\n<p>Open the <code>src/controllers/news.controller.ts</code> file, and import <code>authenticate</code> from jwt authentication.</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"javascript\" data-index=\"20\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk15\">import</span><span class=\"mtk1\"> { </span><span class=\"mtk12\">authenticate</span><span class=\"mtk1\"> } </span><span class=\"mtk15\">from</span><span class=\"mtk1\"> </span><span class=\"mtk8\">&quot;@loopback/authentication&quot;</span></span></code></pre>\n<p>Then on each of the endpoints in your news controller, add <code>@authenticate('jwt')</code> before the <code>NewsController</code> class, which will protect all the routes in <code>NewsController</code>.</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"javascript\" data-index=\"21\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk3\">//...</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    @</span><span class=\"mtk11\">authenticate</span><span class=\"mtk1\">(</span><span class=\"mtk8\">&#39;jwt&#39;</span><span class=\"mtk1\">)</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk3\">//...</span></span></code></pre>\n<p>Perhaps, you may not want to protect all the routes, simply add the <code>@authenticate('jwt')</code> method before the route you wish to protect. You can protect the POST route as follows:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"javascript\" data-index=\"22\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk1\">    @</span><span class=\"mtk11\">authenticate</span><span class=\"mtk1\">(</span><span class=\"mtk8\">&#39;jwt&#39;</span><span class=\"mtk1\">)</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    @</span><span class=\"mtk11\">post</span><span class=\"mtk1\">(</span><span class=\"mtk8\">&#39;/news-models&#39;</span><span class=\"mtk1\">)</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">      @</span><span class=\"mtk11\">response</span><span class=\"mtk1\">(</span><span class=\"mtk7\">200</span><span class=\"mtk1\">, {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">        </span><span class=\"mtk12\">description:</span><span class=\"mtk1\"> </span><span class=\"mtk8\">&#39;NewsModel model instance&#39;</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">        </span><span class=\"mtk12\">content:</span><span class=\"mtk1\"> { </span><span class=\"mtk8\">&#39;application/json&#39;</span><span class=\"mtk12\">:</span><span class=\"mtk1\"> { </span><span class=\"mtk12\">schema:</span><span class=\"mtk1\"> </span><span class=\"mtk11\">getModelSchemaRef</span><span class=\"mtk1\">(</span><span class=\"mtk12\">NewsModel</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 class=\"mtk12\">async</span><span class=\"mtk1\"> </span><span class=\"mtk11\">create</span><span class=\"mtk1\">(</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">        @</span><span class=\"mtk11\">requestBody</span><span class=\"mtk1\">({</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">          </span><span class=\"mtk12\">content:</span><span class=\"mtk1\"> {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">            </span><span class=\"mtk8\">&#39;application/json&#39;</span><span class=\"mtk12\">:</span><span class=\"mtk1\"> {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">              </span><span class=\"mtk12\">schema:</span><span class=\"mtk1\"> </span><span class=\"mtk11\">getModelSchemaRef</span><span class=\"mtk1\">(</span><span class=\"mtk12\">NewsModel</span><span class=\"mtk1\">, {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">                </span><span class=\"mtk12\">title:</span><span class=\"mtk1\"> </span><span class=\"mtk8\">&#39;NewNewsModel&#39;</span><span class=\"mtk1\">,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">                </span><span class=\"mtk12\">exclude:</span><span class=\"mtk1\"> [</span><span class=\"mtk8\">&#39;id&#39;</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 class=\"mtk1\">          },</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">        })</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">        </span><span class=\"mtk12\">newsModel</span><span class=\"mtk1\">: </span><span class=\"mtk12\">Omit</span><span class=\"mtk1\">&lt;</span><span class=\"mtk12\">NewsModel</span><span class=\"mtk1\">, </span><span class=\"mtk8\">&#39;id&#39;</span><span class=\"mtk1\">&gt;,</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">      ): </span><span class=\"mtk10\">Promise</span><span class=\"mtk1\">&lt;</span><span class=\"mtk12\">NewsModel</span><span class=\"mtk1\">&gt; {</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">        return this.newsModelRepository.create(newsModel);</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">      }</span></span></code></pre>\n<h2 id=\"test-your-application\" style=\"position:relative;\"><a href=\"#test-your-application\" aria-label=\"test your application 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>Test Your Application</h2>\n<p>You've implemented user authentication in your REST API and secured the routes against unauthorized users. Let's put your application to the test. Press <code>CTRL-C</code> to exit the server and restart it with the following command:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"bash\" data-index=\"23\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk1\">    npm start</span></span></code></pre>\n<p>If you open the explorer page, you should see the <code>UserController</code> endpoints.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 768px; \"\n    >\n      <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 18.307692307692307%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAECAYAAACOXx+WAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAZ0lEQVQY06XLSwqDMABAwdx/57oX6l4oFKXWBCUWf9HExA889QrpYpYjcqWQssI6R1hXfAhR7rt4j0j0k1ddUriW79JFK31HPjeIh3yTaY205jJFU26iMAMi/RzUv5F+3v4y2J3WBE4VJy+khTQ4gQAAAABJRU5ErkJggg=='); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"User Controller Endpoints\"\n        title=\"User Controller Endpoints\"\n        src=\"/static/2de247e8cdd54f654096ed533e1cf036/e5715/IaV4R43g.png\"\n        srcset=\"/static/2de247e8cdd54f654096ed533e1cf036/a6d36/IaV4R43g.png 650w,\n/static/2de247e8cdd54f654096ed533e1cf036/e5715/IaV4R43g.png 768w,\n/static/2de247e8cdd54f654096ed533e1cf036/5d942/IaV4R43g.png 1343w\"\n        sizes=\"(max-width: 768px) 100vw, 768px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n      />\n    </span></p>\n<p>If you try to execute any query on <code>NewsController</code>, you get a 404 (Unauthorized) error. So, sign up by clicking the <code>/signup</code> endpoint — and log in from the <code>/users/login</code> endpoint. On successful login, copy the token, scroll to the top, click on the <code>Authorize</code> button, and paste the token.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 760px; \"\n    >\n      <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 50.46153846153846%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAKCAYAAAC0VX7mAAAACXBIWXMAAAsTAAALEwEAmpwYAAABnUlEQVQoz42T3W4BURDH91G6SLoIifU4Lt16AC+gqM8L91g0XBKVuvAW+hGx0Rs23QaLxXZZ/55zNvoRrXaSX2Z3dvLfmTlzOFEUIQgCnE4nXC4XXEdPoDGHw/EnPM/D6/UiGAyC8/v9iEQiyGaziMWukEwmkUgkEI8nyPM18vn8WXK5HAqFAkKhEBPl3G437rpdUJvOFjAME7q+xXK5xmZj4L9GxWm1nMfjQavVYsHVSidiOtbrDUzTZLHdbncWw7B/mk6n2YhYhZ3OLczdHuOxAlWdQlFUJk7NOhxwOAMVpZbJZD4F2+02NG2Bfv8eo9EIsixDHg4xeHzCcqadtEeFjv6bIG2ZCjabTViWRSqjFap4JUzUFzxMnjGYk9ibjrmmYTadkblusN/vT1pOpVL2DAUi2Ov1fhz0lqDAwvr4vv39kOhJ0/XhfD4fotEo6vU6isUiyuUyQyLUyhXUpSpupAqq1SpqtRoqFcn+Ltk5pVIJjUYD4XAYtFsuEBBxeSkQdbqkzg94hgMXdHGP8Lb/msdySdzt8SJALsk7MrpLXdldxlkAAAAASUVORK5CYII='); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"Authorizing Users\"\n        title=\"Authorizing Users\"\n        src=\"/static/69a67edb2152d5e20230e726bd62572c/3c051/atU6nqmA.png\"\n        srcset=\"/static/69a67edb2152d5e20230e726bd62572c/a6d36/atU6nqmA.png 650w,\n/static/69a67edb2152d5e20230e726bd62572c/3c051/atU6nqmA.png 760w\"\n        sizes=\"(max-width: 760px) 100vw, 760px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n      />\n    </span></p>\n<p>Now you can execute queries on the <code>NewController</code> endpoints.</p>\n<h2 id=\"user-authentication-with-loginradius\" style=\"position:relative;\"><a href=\"#user-authentication-with-loginradius\" aria-label=\"user authentication 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>User Authentication with Loginradius</h2>\n<p>LoginRadius is a customer identity and access management (CIAM) platform for developers.</p>\n<p>What does this mean for developers like you?</p>\n<p>LoginRadius simplifies the process of user authentication, authorization, and management across web and mobile apps and APIs. It helps developers quickly implement this functionality so that developers, like you, can focus more on building core features that are essential to their apps.</p>\n<p>Loginradius includes a plethora of enticing CIAM features such as passwordless authentication and social SSO (Twitter, Facebook, etc., based single sign-on).</p>\n<p>Implementing user authentication with LoginRadius is a simple procedure. First, sign up for a Developer Pro trial or simply <a href=\"https://accounts.loginradius.com/auth.aspx?action=register\">sign up for a forever free account here</a>.</p>\n<p>And you can explore what LoginRadius can do by using it for a Node.js application. You can learn more by going through <a href=\"https://www.loginradius.com/developers/\">LoginRadius Node.js developer documentation</a></p>\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>This tutorial taught you how to create user authentication in a LoopBack REST API by creating a small news database application.</p>\n<p>You can use the steps outlined in this tutorial to create any type of LoopBack REST API that requires user authentication and authorization.</p>\n<p>I hope you enjoyed this tutorial! Feel free to contact me on <a href=\"https://twitter.com/EkekentaZion\">Twitter</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 .mtk11 { color: #DCDCAA; }\n  .dark-default-dark .mtk3 { color: #6A9955; }\n  .dark-default-dark .mtk12 { color: #9CDCFE; }\n  .dark-default-dark .mtk8 { color: #CE9178; }\n  .dark-default-dark .mtk15 { color: #C586C0; }\n  .dark-default-dark .mtk4 { color: #569CD6; }\n  .dark-default-dark .mtk10 { color: #4EC9B0; }\n  .dark-default-dark .mtk7 { color: #B5CEA8; }\n</style>","frontmatter":{"date":"February 04, 2022","updated_date":null,"description":"Are you building dynamic REST APIs with LoopBack? In this tutorial, you'll learn how to implement user authentication and authorization in a Loopback REST API.","title":"How to Secure Your LoopBack REST API with JWT Authentication","tags":["Authentication","LoopBack","JWT","Node.js"],"pinned":null,"coverImage":{"childImageSharp":{"fluid":{"aspectRatio":1.5037593984962405,"src":"/static/fc88394a30fef65449c1bf39f68e62fc/ee604/secure-loopback-rest-api-with-jwt.png","srcSet":"/static/fc88394a30fef65449c1bf39f68e62fc/69585/secure-loopback-rest-api-with-jwt.png 200w,\n/static/fc88394a30fef65449c1bf39f68e62fc/497c6/secure-loopback-rest-api-with-jwt.png 400w,\n/static/fc88394a30fef65449c1bf39f68e62fc/ee604/secure-loopback-rest-api-with-jwt.png 800w,\n/static/fc88394a30fef65449c1bf39f68e62fc/f3583/secure-loopback-rest-api-with-jwt.png 1200w","sizes":"(max-width: 800px) 100vw, 800px"}}},"author":{"id":"Ekekenta Odionyenfe Clinton","github":"icode247","avatar":null}}}},{"node":{"excerpt":"Authentication remains at the core of any application with user data and accounts. It ensures that only the authorized person is accessing…","fields":{"slug":"/engineering/developers-can-get-rid-of-password-based-authentication/"},"html":"<p>Authentication remains at the core of any application with user data and accounts. It ensures that only the authorized person is accessing the data and account. So far, Password-based authentication has been prevalent that developers mostly use.</p>\n<p>Unfortunately, passwords are no longer a wise choice for developers to ensure secure and seamless authentication. Let’s see why:</p>\n<ul>\n<li><strong>Vulnerable to cyberattacks:</strong> Passwords are still used as an authentication mechanism because of the long-standing efforts developers and technology industry leaders are delivering to secure the passwords. But hackers are in constant pursuit to breach passwords through different cyber-attacks and as a result, nearly 1 million passwords get stolen each week.</li>\n<li><strong>Security is subjected to chosen passwords:</strong> Users tend to use repetitive or insecure passwords for their accounts, which weakens the authentication security. If a user's password is leaked in one breach, it can impact the security of other applications where the user is using the same password.</li>\n<li><strong>Easily forgotten by users:</strong> Considering the risks password-based authentication poses to an application, developers need to include password policies and enforce restrictive logic in their authentication algorithms to accept strong passwords. This makes it even more difficult for the user to remember their account password. Such setup results in higher forgotten password requests requiring more development and support resources.</li>\n<li><strong>Efforts in securing and managing password-based authentication:</strong> Password policies, security algorithms, encryption techniques have become minimal viable requirements to manage password-based authentication. This increases the development efforts involved in developing and managing password-based authentication.</li>\n</ul>\n<p>Before talking about the solution in detail, let’s get deeper into the problem and see what are the common cyber-attacks faced by password-based authentication.</p>\n<h2 id=\"common-cyber-attacks-with-password-based-authentication\" style=\"position:relative;\"><a href=\"#common-cyber-attacks-with-password-based-authentication\" aria-label=\"common cyber attacks with password based authentication 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>Common Cyber-attacks with Password-based Authentication</h2>\n<p>The following is the list of common password attacks. It also explains what additional efforts developers need to put in to fight these cyber-attacks and protect user data:</p>\n<ul>\n<li><strong>Brute force:</strong> This password cracking attack use automation to guess a password millions of times. It tries all the possible combinations and permutations of passwords to exploit weak passwords like abcd@9876.</li>\n</ul>\n<p>To protect against this attack, developers have to develop security features like suspending or locking user accounts on multiple subsequent attempts to log in with an incorrect password.</p>\n<ul>\n<li><strong>Credential Stuffing:</strong> It is a type of identity theft where the attacker injects breached or leaked credentials of one account to access numerous other user accounts.</li>\n</ul>\n<p>To protect against this attack, developers have to ensure that users are not using insecure or previously breached passwords.</p>\n<ul>\n<li><strong>Keylogging:</strong> It records the user's keyboard interactions and key presses. Keylogger programs are used to record what users are typing on their keyboard and send the logged data to the creator.</li>\n</ul>\n<p>To protect against this attack, developers need to introduce 2FA (two-factor authentication). Stakes are high in this case as a lot depends on how users take security measures.</p>\n<ul>\n<li><strong>Man-in-the-Middle (MiTM):</strong> In this type of attack, the attacker sits in between the target user and the web application and deciphers all traffic passed among each other such as username, passwords, etc.</li>\n</ul>\n<p>That is where developers have to be cautious, keeping all the data-in-transit encrypted.</p>\n<p>Luckily getting rid of passwords from the authentication mechanism can address all the above-stated problems. Eliminating passwords from internet space is certainly not a 1-day thing, but the responsibility lies with developers.</p>\n<p>Developers should introduce more secure and user-friendly authentication methods to their application users such as magic links, single sign-on (SSO), biometric, hardware-based authentication.</p>\n<h2 id=\"alternatives-to-password-based-authentication\" style=\"position:relative;\"><a href=\"#alternatives-to-password-based-authentication\" aria-label=\"alternatives to password based authentication 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>Alternatives to Password-based Authentication</h2>\n<h3 id=\"passwordless-authentication\" style=\"position:relative;\"><a href=\"#passwordless-authentication\" aria-label=\"passwordless authentication 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>Passwordless Authentication</h3>\n<p>It does the user authentication based on the \"possession factor.\" That is where developers find passwordless authentication trustworthy, as the authentication uses a phone number, email ID, or authenticator app to cater to an OTP, one-time link, or code respectively to verify the user.</p>\n<p>Through this, developers can improve the user experience of the application and reduce risk while minimizing the total cost of storing the login credentials. Users will employ the one-time link or OTP only if they are logged into their email or possess the phone for SMS. This assures the developer a better security.</p>\n<h3 id=\"single-sign-on\" style=\"position:relative;\"><a href=\"#single-sign-on\" aria-label=\"single sign on 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>Single Sign-on</h3>\n<p>Almost all websites demand some form of authentication to access their content and features. Single sign-on authentication has become a standard authentication method for website logins.</p>\n<p>Developers can integrate the single sign-on feature in their web applications to facilitate users to securely authenticate multiple apps and websites by leveraging one set of login credentials.</p>\n<p>Through SSO, developers can implement multi-factor authentication implicitly. It uses a federated identity management architecture that relies on open standard protocols to exchange identity and authentication information among these protocols. That makes implementing the security easier for developers.</p>\n<h3 id=\"biometric-authentication\" style=\"position:relative;\"><a href=\"#biometric-authentication\" aria-label=\"biometric authentication 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>Biometric Authentication</h3>\n<p>Biometrics refers to the user's physical characteristics allowing them to identify uniquely on a digital platform. Instead of typing letters, numbers, and symbols (for passwords), biometric authentication uses biometric systems to calculate and estimate the user's physical attributes. Facial recognition, tiny impressions made by fingerprints, and vocal cadence are well-known biometric authentication techniques.</p>\n<p>It is gaining traction because developers do not have to maintain a separate database of usernames and passwords since the authentication takes place from the user device rather than the application's database.</p>\n<h3 id=\"smart-authentication\" style=\"position:relative;\"><a href=\"#smart-authentication\" aria-label=\"smart authentication 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>Smart Authentication</h3>\n<p>Most in-house developers and smart device vendors leverage this authentication technique to avoid password authentication. This authentication mostly uses QR codes or link-based login approaches. Here the one-time link or the QR code uniquely generates the verification process that helps initiate the user login process without any password.</p>\n<h3 id=\"hardware-based-authentication\" style=\"position:relative;\"><a href=\"#hardware-based-authentication\" aria-label=\"hardware based authentication 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>Hardware-based authentication</h3>\n<p>In this approach, the authentication uses a dedicated plug-and-run physical device belonging to the authorized user. These versatile security devices help users log in to desktops, Wi-Fi, websites, and other applications.</p>\n<p>FIDO2 devices are touch-sensed USB sticks that enable hardware authentication and follow the FIDO Alliance standards and specifications. Leveraging this authentication mechanism is a plus point as the developers do not have to maintain a secure database for the login credentials.</p>\n<h2 id=\"can-we-actually-get-rid-of-passwords\" style=\"position:relative;\"><a href=\"#can-we-actually-get-rid-of-passwords\" aria-label=\"can we actually get rid of passwords 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>Can we actually get rid of passwords?</h2>\n<p>For decades, password-based authentication has been the mainstay for security and user verification. On average, almost all online users have 20 to 30 login credentials for different applications and sites. Password logins have become so common that changing the authentication trend and adopting a new authentication approach will take time.</p>\n<p>All the alternatives mentioned in this article can help minimize using passwords to a significant level. It's time developers should seriously ponder the problems that passwords can create for themselves and opt for reasonable alternatives as per the situation, requirements, or policy standards.</p>\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>Passwords are becoming more like a liability rather than a security asset. Hence, to get rid of them, developers are leveraging other means of authentication that are more reliable and less susceptible to security breaches and threats.</p>\n<p>Worried about efforts involved in implementing these alternative authentication methods from scratch? <a href=\"https://accounts.loginradius.com/auth.aspx?action=register&#x26;return_url=https://dashboard.loginradius.com/login&#x26;plan=pro\">LoginRadius</a> identity platform comes with these authentication techniques so that developers do not have to implement them from scratch in their applications to provide alternate authentication.</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":"January 31, 2022","updated_date":null,"description":"Authentication remains at the core of any application with user data and accounts. It ensures that only the authorized person is accessing the data and account. So far, Password-based authentication has been prevalent that developers mostly use.","title":"When Can Developers Get Rid of Password-based Authentication?","tags":["Authentication"],"pinned":null,"coverImage":{"childImageSharp":{"fluid":{"aspectRatio":1.5037593984962405,"src":"/static/ec99b982c7381590d9835756acbaf197/ee604/password-dev.png","srcSet":"/static/ec99b982c7381590d9835756acbaf197/69585/password-dev.png 200w,\n/static/ec99b982c7381590d9835756acbaf197/497c6/password-dev.png 400w,\n/static/ec99b982c7381590d9835756acbaf197/ee604/password-dev.png 800w,\n/static/ec99b982c7381590d9835756acbaf197/f3583/password-dev.png 1200w","sizes":"(max-width: 800px) 100vw, 800px"}}},"author":{"id":"Kundan Singh","github":null,"avatar":null}}}}]},"markdownRemark":{"excerpt":"Google has prepared a roadmap to restrict third-party cookies in Chrome. Since 04 January 2024, Chrome has rolled out third-party cookie…","fields":{"slug":"/engineering/identity-impact-of-google-chrome-thirdparty-cookie-restrictions/"},"html":"<p>Google has prepared a roadmap to restrict third-party cookies in Chrome. Since 04 January 2024, Chrome has rolled out third-party cookie restrictions for 1% of stable clients and 20% of Canary, Dev, and Beta clients.</p>\n<p><strong>What does it mean for user authentication?</strong></p>\n<p>On one hand, Google believes third-party cookies are widely used for cross-site tracking, greatly affecting user privacy. Hence, Google wants to phase out (or restrict) supporting third-party cookies in Chrome by early Q2 2025 (subject to regulatory processes).</p>\n<p>On the other hand, Google introduced Privacy Sandbox to support the use cases (other than cross-site tracking and advertising) previously implemented using third-party cookies.</p>\n<p>In this article, we’ll discuss:</p>\n<ul>\n<li>How is user authentication (identity) affected?</li>\n<li>What is Google offering as part of Privacy Sandbox to support various identity use cases when third-party cookies are phased out?</li>\n</ul>\n<h2 id=\"how-is-user-authentication-affected\" style=\"position:relative;\"><a href=\"#how-is-user-authentication-affected\" aria-label=\"how is user authentication affected 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 is User Authentication Affected?</h2>\n<p>Third-party cookie restrictions affect user authentication in three ways, as follows.</p>\n<h3 id=\"external-identity-providers\" style=\"position:relative;\"><a href=\"#external-identity-providers\" aria-label=\"external identity providers 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>External Identity Providers</h3>\n<p>If your website or app uses an external Identity Provider (IdP) — like LoginRadius, the IdP sets a third-party cookie when the user authenticates on your app.</p>\n<h3 id=\"web-sso\" style=\"position:relative;\"><a href=\"#web-sso\" aria-label=\"web sso 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>Web SSO</h3>\n<p>If you have multiple apps across domains within your organization and authentication is handled using an IdP (internal or external) with web SSO, you already use third-party cookies to facilitate seamless access for each user using a single set of credentials.</p>\n<p>If you have implemented web SSO with one primary domain and multiple sub-domains of the primary domain, third-party cookie restrictions may not apply. For now, Google doesn’t consider the cookies set by sub-domains as third-party cookies, although this stance may change in the future.</p>\n<p>For example, you have apps at <code>example.com</code>, <code>travel.example.com</code>, <code>stay.example.com</code>, and web SSO is handled by <code>auth.example.com</code>. In this case, third-party cookie restrictions don’t apply.</p>\n<h3 id=\"federated-sso\" style=\"position:relative;\"><a href=\"#federated-sso\" aria-label=\"federated sso 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>Federated SSO</h3>\n<p>Federated SSO is similar to, albeit different from, web SSO. It can handle multiple IdPs and applications—aka., Service Providers (SPs)—spanning multiple organizations. It can also implement authentication scenarios that are usually implemented through web SSO.</p>\n<p>Usually, authentication is handled on a separate pop-up or page when the user wants to authenticate rather than on the application or website a user visits. </p>\n<p>For example, you already use federated SSO if you facilitate authentication for a set of apps through multiple social identity providers as well as traditional usernames and passwords.</p>\n<blockquote>\n<p><strong>Note</strong>: It is also possible to store tokens locally, not within cookies. In this case, third-party cookie restrictions won’t affect token-based authentication. However, the restrictions still affect authentication where tokens are stored within third-party cookies (a common and secure method).</p>\n</blockquote>\n<h2 id=\"chromes-alternatives-for-third-party-cookies\" style=\"position:relative;\"><a href=\"#chromes-alternatives-for-third-party-cookies\" aria-label=\"chromes alternatives for third party cookies 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>Chrome’s Alternatives for Third-Party Cookies</h2>\n<p>Google has been developing alternative features and capabilities for Chrome to replace third-party cookies as part of its Privacy Sandbox for Web initiative.</p>\n<p>Specific to authentication, Google recommends the following:</p>\n<ol>\n<li>Cookies Having Independent Partitioned State (CHIPS)</li>\n<li>Storage Access API</li>\n<li>Related Website Sets</li>\n<li>Federated Credential Management (FedCM) API</li>\n</ol>\n<h3 id=\"cookies-having-independent-partitioned-state-chips\" style=\"position:relative;\"><a href=\"#cookies-having-independent-partitioned-state-chips\" aria-label=\"cookies having independent partitioned state chips 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>Cookies Having Independent Partitioned State (CHIPS)</h3>\n<p><a href=\"https://developers.google.com/privacy-sandbox/3pcd/chips\">CHIPS</a> are a restricted way of setting third-party cookies on a top-level site without making them accessible on other top-level sites. Thus, they limit cross-site tracking and enable specific cross-site functionalities, such as maps, chat, and payment embeds.</p>\n<p>For example, a user visits <code>a.com</code> with a map embed from <code>map-example.com</code>, which can set a partitioned cookie that is only accessible on a.com. </p>\n<p>If the user visits <code>b.com</code> with a map embed from <code>map-example.com</code>, it cannot access the partitioned cookie set on <code>a.com</code>. It has to create a separate partitioned cookie specific to <code>b.com</code>, thus blocking cross-site tracking yet allowing limited cross-site functionality.</p>\n<p>You should specifically opt for partitioned cookies (CHIPS), which are set with partitioned and secure cookie attributes.</p>\n<p>If you’re using an external identity provider for your application, CHIPS is a good option to supplant third-party cookie restrictions. </p>\n<p>However, CHIPS may not be ideal if you have a web SSO or federated SSO implementation. It creates separate partitioned cookies for each application with a separate domain, which can increase complexity and create compatibility issues.</p>\n<h3 id=\"storage-access-api\" style=\"position:relative;\"><a href=\"#storage-access-api\" aria-label=\"storage access 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>Storage Access API</h3>\n<p>With <a href=\"https://developers.google.com/privacy-sandbox/3pcd/storage-access-api\">Storage Access API</a>, you can access the local storage in a third-party context through iframes, similar to when users visit it as a top-level site in a first-party context. That is, it gives access to unpartitioned cookies and storage.</p>\n<p>Storage Access API requires explicit user approval to grant access, similar to locations, camera, and microphone permissions. If the user denies access, unpartitioned cookies and storage won’t be accessible in a third-party context.</p>\n<p>It is most suitable when loading cross-site resources and interactions, such as:</p>\n<p>Verifying user sessions when allowing interactions on an embedded social post or providing personalization for an embedded video.\nEmbedded documents requiring user verification status to be accessible.</p>\n<p>As it requires explicit user approval, it is advisable to use Storage Access API when you can’t implement an identity use case with the other options.</p>\n<h3 id=\"related-website-sets\" style=\"position:relative;\"><a href=\"#related-website-sets\" aria-label=\"related website sets 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>Related Website Sets</h3>\n<p>With <a href=\"https://developers.google.com/privacy-sandbox/3pcd/related-website-sets\">Related Website Sets</a>, you can declare a <code>primary</code> website and <code>associatedSites</code> for limited purposes to grant third-party cookie access and local storage for a limited number of sites.</p>\n<p>Chrome automatically recognizes related website sets declared, accepted, and maintained in this open-source GitHub repository: <a href=\"https://github.com/GoogleChrome/related-website-sets\">Related Website Sets</a></p>\n<p>It provides access through Storage Access API directly without prompting for user approval, but only after the user interacts with the relevant iframe.</p>\n<p>It is important to declare a limited number of domains in related website sets that are meaningful and used for specific purposes. Google may block or suspend any exploitative use of this feature.</p>\n<p>The top-level site can also request approval for specific cross-site resources and scripts to Storage Access API using <code>resuestStorageAccessFor()</code> API.</p>\n<p>If you’re using an external identity provider for your web application, you can declare the domain of the identity provider in the related set to ensure limited third-party cookies and storage access to the identity provider, thus ensuring seamless user authentication.</p>\n<p>Related Website Sets can also work to supplement third-party cookie restrictions in web SSO and federated SSO if the number of web applications (or domains) is limited.</p>\n<h3 id=\"federated-credential-management-fedcm-api\" style=\"position:relative;\"><a href=\"#federated-credential-management-fedcm-api\" aria-label=\"federated credential management fedcm 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>Federated Credential Management (FedCM) API</h3>\n<p>FedCM API enables federated SSO without third-party cookies.</p>\n<p>With FedCM API, a user follows these steps for authentication:</p>\n<ol>\n<li>The User navigates to a Service Provider (SP) — aka., Relying Party (RP)</li>\n<li>As the user requests to authenticate, the SP requests the browser through FedCM API to initiate authentication.</li>\n<li>The browser displays a list of available identity providers (supported by the RP), such as social IdPs like Google, Apple, LinkedIn, and Facebook, or other OAuth IdPs like LoginRadius.</li>\n<li>Once the user selects an IdP, the browser communicates with the IdP. Upon valid authentication, the IdP generates a secure token.\nThe browser delivers this secure token to the RP to facilitate user authorization.</li>\n</ol>\n<p>You can access a user demo of FedCM here: <a href=\"https://fedcm-rp-demo.glitch.me/\">FedCM</a>. </p>\n<p>For more information about implementing federated SSO with FedCM API, go through the <a href=\"https://developers.google.com/privacy-sandbox/3pcd/fedcm-developer-guide\">FedCM developer guide</a>.</p>\n<h2 id=\"how-is-loginradius-preparing-for-the-third-party-cookie-phase-out\" style=\"position:relative;\"><a href=\"#how-is-loginradius-preparing-for-the-third-party-cookie-phase-out\" aria-label=\"how is loginradius preparing for the third party cookie phase out 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 is LoginRadius Preparing for the Third-party Cookie Phase-out?</h2>\n<p>Firstly, we’re committed to solving our customers' user identity pain points — and preparing for the third-party cookies phase-out is no different.</p>\n<p>We’ll implement the most relevant and widely useful solutions to facilitate a smooth transition for our customers.</p>\n<p>Please subscribe to our blog for more information. We’ll update you on how we help with the third-party cookie phase-out.</p>\n<h2 id=\"in-conclusion\" style=\"position:relative;\"><a href=\"#in-conclusion\" aria-label=\"in 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>In Conclusion</h2>\n<p>The proposed changes to phase out third-party cookies and suggested alternatives are evolving as Google has been actively collaborating and discussing changes with the border community.</p>\n<p>Moreover, browsers like Firefox, Safari, and Edge may approach restricting third-party cookies differently than Google does.</p>\n<p>From LoginRadius, we’ll keep you updated on what we’re doing as a leading Customer Identity and Access Management (CIAM) vendor to prepare for the third-party cookie phase-out.</p>\n<h2 id=\"glossary\" style=\"position:relative;\"><a href=\"#glossary\" aria-label=\"glossary 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>Glossary</h2>\n<p><strong>Top-level site</strong>: It is the primary site a user has visited.</p>\n<p><strong>First-party cookie</strong>: A cookie set by the top-level site.</p>\n<p><strong>Third-party cookie</strong>: A cookie set by a domain other than the top-level site. For example, let’s assume that a user has visited <code>a.com</code>, which might use an embed from <code>loginradius.com</code> to facilitate authentication. If <code>loginradius.com</code> sets a cookie when the user visits <code>a.com</code>, it is called a third-party cookie as the user hasn’t directly visited <code>loginradius.com</code>.</p>\n<h2 id=\"references\" style=\"position:relative;\"><a href=\"#references\" aria-label=\"references 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>References</h2>\n<ul>\n<li><a href=\"https://developers.google.com/privacy-sandbox/3pcd/prepare/prepare-for-phaseout\">Changes to Chrome's treatment of third-party cookies</a></li>\n<li><a href=\"https://developers.google.com/privacy-sandbox/3pcd/guides/identity\">Check the impact of the third-party cookie changes on your sign-in workflows</a></li>\n</ul>\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 08, 2024","updated_date":null,"description":"Google Chrome has planned to phase out third-party cookies, which will affect different website functionalities depending on third-party cookies. This blog focuses on how this phase-out affects identity and user authentication and discusses alternatives for overcoming challenges.","title":"How Chrome’s Third-Party Cookie Restrictions Affect User Authentication?","tags":["Identity","Cookies","Chrome"],"pinned":null,"coverImage":{"childImageSharp":{"fluid":{"aspectRatio":1.5037593984962405,"src":"/static/eb7396060c0adc430dbed2d04b63d431/ee604/third-party-cookies-phaseout-chrome.png","srcSet":"/static/eb7396060c0adc430dbed2d04b63d431/69585/third-party-cookies-phaseout-chrome.png 200w,\n/static/eb7396060c0adc430dbed2d04b63d431/497c6/third-party-cookies-phaseout-chrome.png 400w,\n/static/eb7396060c0adc430dbed2d04b63d431/ee604/third-party-cookies-phaseout-chrome.png 800w,\n/static/eb7396060c0adc430dbed2d04b63d431/f3583/third-party-cookies-phaseout-chrome.png 1200w","sizes":"(max-width: 800px) 100vw, 800px"}}},"author":{"id":"Raghunath Reddy","github":"raghunath-r-a","avatar":null}}}},"pageContext":{"limit":6,"skip":18,"currentPage":4,"type":"//engineering//","numPages":52,"pinned":"17fa0d7b-34c8-51c4-b047-df5e2bbaeedb"}},"staticQueryHashes":["1171199041","1384082988","2100481360","23180105","528864852"]}