{
    "componentChunkName": "component---src-pages-blog-markdown-remark-fields-slug-js",
    "path": "/blog/how-to-set-up-social-and-email-password-login-with-reactjs",
    "result": {"data":{"markdownRemark":{"html":"<p>One of the most challenging parts of setting up a new application is the backend logins and account management. If not correctly implemented and designed, handling user registrations and maintaining user accounts can be downright complicated and bug-prone. In this tutorial, we’ll walk you through setting up a user authentication workflow using SuperTokens on a ReactJS application with ExpressJS as the backend. This will include an email-password authentication with popular social providers like Google, GitHub, and Apple.</p>\n<h2 id=\"how-does-supertokens-work\" style=\"position:relative;\"><a href=\"#how-does-supertokens-work\" aria-label=\"how does supertokens work 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 does SuperTokens Work?</h2>\n<p>SuperTokens is an open-source alternative to proprietary login providers like Auth0 or AWS Cognito. You can use SuperTokens for just logging in, or just session management, or both. Here’s an illustration of the architecture of SuperTokens managed service:</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 630px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/de7e40d7d08aca3b124911b202823f7a/20785/managedservice_flow-%E2%80%93-21.png\"\n    style=\"display: block\"\n    target=\"_blank\"\n    rel=\"noopener\"\n  >\n    <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 43.67088607594937%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAJCAYAAAAywQxIAAAACXBIWXMAAAsTAAALEwEAmpwYAAABoElEQVQoz22SzW7TQBzE8xBVsru298Nre/2ZhDSotJVA3HogBw7NlSu0jwDiAVLOvA2ceK9f5Q1Ooaql8X/Xmpmd1XimlEJIicsyGmMJxpImCVLKCK0lVXmEziRCSHSqCC6hsopgVZxOq8ifjS+VJGgxx4szcnFGqiTjQVIqnEsYupS+TcldipAKkyUsK01TaGqv47qw6ZOhMZqbm1v2+3tu9/dcXLxFiAXGGFarNSE0tG0bMXLHw1wROB8C77eBvGyw1h0NkySJ4t+//jA9375+ZyEEZVXR9z1N03D5ZsX2fEnhPWXhCcOGzx/W/PzUkPqGwrspoULrjLsvdzw8/OBwOLDb7ciMwbo8mnVdS99PCU00rbuBd9uGj9cVvmrwuXu68jGlIM9dFEghcFWNDzWvt1s2mw1Xl2uur15RlgVZlmGNoW57qnbA53nsIRrGloWIpOVySdd1x4aFwFrDMAzUITD0dUzqnDv9AaNGZ1ksL5ar1N+W1fHDfD5nsVicGh7nmHhMOMIYe+JOc8K0n/1LmPBcEEKgrmuU+l/8kuYRAG8Go9Ur0HsAAAAASUVORK5CYII='); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"supertokens managed service architecture\"\n        title=\"supertokens managed service architecture\"\n        src=\"/static/de7e40d7d08aca3b124911b202823f7a/f058b/managedservice_flow-%E2%80%93-21.png\"\n        srcset=\"/static/de7e40d7d08aca3b124911b202823f7a/c26ae/managedservice_flow-%E2%80%93-21.png 158w,\n/static/de7e40d7d08aca3b124911b202823f7a/6bdcf/managedservice_flow-%E2%80%93-21.png 315w,\n/static/de7e40d7d08aca3b124911b202823f7a/f058b/managedservice_flow-%E2%80%93-21.png 630w,\n/static/de7e40d7d08aca3b124911b202823f7a/40601/managedservice_flow-%E2%80%93-21.png 945w,\n/static/de7e40d7d08aca3b124911b202823f7a/78612/managedservice_flow-%E2%80%93-21.png 1260w,\n/static/de7e40d7d08aca3b124911b202823f7a/20785/managedservice_flow-%E2%80%93-21.png 1307w\"\n        sizes=\"(max-width: 630px) 100vw, 630px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n        decoding=\"async\"\n      />\n  </a>\n    </span></p>\n<p>As we can see, this is primarily built on top of three components. First, we have the front-end client. This is responsible for rendering the login UI widgets and managing session tokens automatically. Second, we have the BackendAPI which provides APIs for sign-up, sign-in, signout, session refreshing etc. Lastly, we have the SuperTokens managed service which is an HTTP service that contains the core logic for auth. It’s also responsible for interfacing with the database.</p>\n<p>When self-hosted the architecture is almost similar, except that you will need to run the SuperTokens core yourself and connect it to your own database:</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 630px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/a2dc8ea1d0a9f16dcc31b93e9ed58b55/20785/selfhosted-%E2%80%93-3.png\"\n    style=\"display: block\"\n    target=\"_blank\"\n    rel=\"noopener\"\n  >\n    <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 43.67088607594937%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAJCAYAAAAywQxIAAAACXBIWXMAAAsTAAALEwEAmpwYAAABtElEQVQoz22Sa27UMBSFs4hqJn4kcZ5O7GQetJ0gQEJFI9BsYEDqfx6i0uyjw0aQ2An8YkMfiqdDUYWlK/uc43t8fe1IS0WXGdrMUCQJsRAIIZFSUFcCWwuKfOJO/DRP2gkLUm0osxaTVgFHWgqK+QVlfEEaz5BKIYVAa4XrNIPX2EajJl5KtNbMhEZpHYzzrKIuW+qiC3p0ff2C/fs79vuv7HYfMCYjjmP6vsf7gbbr6Jyjrk8VlFXN7nlL7yxap5RVzti/w7UDOlFEnz5+4Tx+/fxNXddkJg+Gzjkunw2MmyXedZRlQb9Y8eNu4M3Yk+U11uV8fv2dcXiL1HOi7XbL8fiN+/sjh8MBay1JZsLsvWMYPG3bhiiLgsa23N60rPuWNDM0tuJmfcvCX50qnK6RJJqyLInn81CdsR2LxYJx3HB1ueTVyzXrVY+UiqqqaPySxtrQwyRJkMmMJNUo+WA4nb5arciyU/+UFOG63nucs/TehVYETSmyNEEr9felpXhcR9PLTBtns9nDl5AIKUPiZLrZbGgaG/igiccvc+b+jeipcMbTIcaYUGWapgE/Tf6f6R8fDQjt5nrXjgAAAABJRU5ErkJggg=='); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"supertokens self hosted service architecture\"\n        title=\"supertokens self hosted service architecture\"\n        src=\"/static/a2dc8ea1d0a9f16dcc31b93e9ed58b55/f058b/selfhosted-%E2%80%93-3.png\"\n        srcset=\"/static/a2dc8ea1d0a9f16dcc31b93e9ed58b55/c26ae/selfhosted-%E2%80%93-3.png 158w,\n/static/a2dc8ea1d0a9f16dcc31b93e9ed58b55/6bdcf/selfhosted-%E2%80%93-3.png 315w,\n/static/a2dc8ea1d0a9f16dcc31b93e9ed58b55/f058b/selfhosted-%E2%80%93-3.png 630w,\n/static/a2dc8ea1d0a9f16dcc31b93e9ed58b55/40601/selfhosted-%E2%80%93-3.png 945w,\n/static/a2dc8ea1d0a9f16dcc31b93e9ed58b55/78612/selfhosted-%E2%80%93-3.png 1260w,\n/static/a2dc8ea1d0a9f16dcc31b93e9ed58b55/20785/selfhosted-%E2%80%93-3.png 1307w\"\n        sizes=\"(max-width: 630px) 100vw, 630px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n        decoding=\"async\"\n      />\n  </a>\n    </span></p>\n<h3 id=\"setting-up-a-reactjs-project-and-initialising-supertokens\" style=\"position:relative;\"><a href=\"#setting-up-a-reactjs-project-and-initialising-supertokens\" aria-label=\"setting up a reactjs project and initialising supertokens 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 a ReactJS Project and Initialising SuperTokens</h3>\n<p>First up, let’s create our working environment; for this, we will be using the most popular <code class=\"language-text\">create-react-app</code> command.</p>\n<blockquote>\nTo get this command running make sure to have Node >= 14.0.0 and npm >= 5.6 installed on your machine.\n</blockquote>\n<div\n              class=\"gatsby-code-button-container\"\n              data-toaster-id=\"19830313360522680000\"\n              data-toaster-class=\"gatsby-code-button-toaster\"\n              data-toaster-text-class=\"gatsby-code-button-toaster-text\"\n              data-toaster-text=\"Copied!\"\n              data-toaster-duration=\"3500\"\n              onClick=\"copyToClipboard(`npx create-react-app my-demo-app`, `19830313360522680000`)\"\n            >\n              <div\n                class=\"gatsby-code-button\"\n                data-tooltip=\"\"\n              >\n                <svg class=\"gatsby-code-button-icon\" xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\"><path fill=\"none\" d=\"M0 0h24v24H0V0z\"/><path d=\"M16 1H2v16h2V3h12V1zm-1 4l6 6v12H6V5h9zm-1 7h5.5L14 6.5V12z\"/></svg>\n              </div>\n            </div>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\">npx create-react-app my-demo-app</code></pre></div>\n<p>This will create a <code class=\"language-text\">my-demo-app</code> folder with all the directories and files required to build our react app. Navigate to the newly created project in the terminal and run the application using <code class=\"language-text\">yarn start</code> command. This will open the browser on <code class=\"language-text\">http://localhost:3000</code> with a default react page.\nNow, install the SuperTokens React SDK by navigating to the <code class=\"language-text\">my-demo-app</code> directory and running the following command:</p>\n<div\n              class=\"gatsby-code-button-container\"\n              data-toaster-id=\"77612243292490660000\"\n              data-toaster-class=\"gatsby-code-button-toaster\"\n              data-toaster-text-class=\"gatsby-code-button-toaster-text\"\n              data-toaster-text=\"Copied!\"\n              data-toaster-duration=\"3500\"\n              onClick=\"copyToClipboard(`cd my-demo-app`, `77612243292490660000`)\"\n            >\n              <div\n                class=\"gatsby-code-button\"\n                data-tooltip=\"\"\n              >\n                <svg class=\"gatsby-code-button-icon\" xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\"><path fill=\"none\" d=\"M0 0h24v24H0V0z\"/><path d=\"M16 1H2v16h2V3h12V1zm-1 4l6 6v12H6V5h9zm-1 7h5.5L14 6.5V12z\"/></svg>\n              </div>\n            </div>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token builtin class-name\">cd</span> my-demo-app</code></pre></div>\n<div\n              class=\"gatsby-code-button-container\"\n              data-toaster-id=\"19725713416665313000\"\n              data-toaster-class=\"gatsby-code-button-toaster\"\n              data-toaster-text-class=\"gatsby-code-button-toaster-text\"\n              data-toaster-text=\"Copied!\"\n              data-toaster-duration=\"3500\"\n              onClick=\"copyToClipboard(`yarn add supertokens-auth-react`, `19725713416665313000`)\"\n            >\n              <div\n                class=\"gatsby-code-button\"\n                data-tooltip=\"\"\n              >\n                <svg class=\"gatsby-code-button-icon\" xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\"><path fill=\"none\" d=\"M0 0h24v24H0V0z\"/><path d=\"M16 1H2v16h2V3h12V1zm-1 4l6 6v12H6V5h9zm-1 7h5.5L14 6.5V12z\"/></svg>\n              </div>\n            </div>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token function\">yarn</span> <span class=\"token function\">add</span> supertokens-auth-react</code></pre></div>\n<blockquote>\nThis SDK will provide the login UI as react components, and will also help with session management. \n</blockquote>\n<p>Next, let’s set up the SuperTokens SDK by using the <code class=\"language-text\">init</code> function. Navigate to <code class=\"language-text\">App.js</code> under the <code class=\"language-text\">src</code> directory and paste the following snippet:</p>\n<div\n              class=\"gatsby-code-button-container\"\n              data-toaster-id=\"9010861988944607000\"\n              data-toaster-class=\"gatsby-code-button-toaster\"\n              data-toaster-text-class=\"gatsby-code-button-toaster-text\"\n              data-toaster-text=\"Copied!\"\n              data-toaster-duration=\"3500\"\n              onClick=\"copyToClipboard(`//my-demo-app/src/App.js\n\nimport logo from &quot;./logo.svg&quot;;\nimport &quot;./App.css&quot;;\n\nimport React from &quot;react&quot;;\n\n// Imports from SuperTokens\n\nimport SuperTokens from &quot;supertokens-auth-react&quot;;\nimport ThirdPartyEmailPassword, {\n Github,\n Google,\n Apple,\n} from &quot;supertokens-auth-react/recipe/thirdpartyemailpassword&quot;;\n\nimport Session from &quot;supertokens-auth-react/recipe/session&quot;;\n\n// SuperTokens INIT\n\nSuperTokens.init({\n appInfo: {\n   appName: &quot;My Demo App&quot;,\n   apiDomain: &quot;http://localhost:3001&quot;,\n   websiteDomain: &quot;http://localhost:3000&quot;,\n },\n recipeList: [\n   ThirdPartyEmailPassword.init({\n     signInAndUpFeature: {\n       providers: [\n         Github.init(),\n         Google.init(),\n         Apple.init(),\n       ],\n     },\n   }),\n   Session.init(),\n ],\n});\n\n\nfunction App() {\n return (\n\t// Your App Code\n );\n}\n\nexport default App;`, `9010861988944607000`)\"\n            >\n              <div\n                class=\"gatsby-code-button\"\n                data-tooltip=\"\"\n              >\n                <svg class=\"gatsby-code-button-icon\" xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\"><path fill=\"none\" d=\"M0 0h24v24H0V0z\"/><path d=\"M16 1H2v16h2V3h12V1zm-1 4l6 6v12H6V5h9zm-1 7h5.5L14 6.5V12z\"/></svg>\n              </div>\n            </div>\n<div class=\"gatsby-highlight\" data-language=\"tsx\"><pre class=\"language-tsx\"><code class=\"language-tsx\"><span class=\"token comment\">//my-demo-app/src/App.js</span>\n\n<span class=\"token keyword\">import</span> logo <span class=\"token keyword\">from</span> <span class=\"token string\">\"./logo.svg\"</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">import</span> <span class=\"token string\">\"./App.css\"</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">import</span> React <span class=\"token keyword\">from</span> <span class=\"token string\">\"react\"</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">// Imports from SuperTokens</span>\n\n<span class=\"token keyword\">import</span> SuperTokens <span class=\"token keyword\">from</span> <span class=\"token string\">\"supertokens-auth-react\"</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">import</span> ThirdPartyEmailPassword<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span>\n Github<span class=\"token punctuation\">,</span>\n Google<span class=\"token punctuation\">,</span>\n Apple<span class=\"token punctuation\">,</span>\n<span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">\"supertokens-auth-react/recipe/thirdpartyemailpassword\"</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">import</span> Session <span class=\"token keyword\">from</span> <span class=\"token string\">\"supertokens-auth-react/recipe/session\"</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">// SuperTokens INIT</span>\n\nSuperTokens<span class=\"token punctuation\">.</span><span class=\"token function\">init</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>\n appInfo<span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n   appName<span class=\"token operator\">:</span> <span class=\"token string\">\"My Demo App\"</span><span class=\"token punctuation\">,</span>\n   apiDomain<span class=\"token operator\">:</span> <span class=\"token string\">\"http://localhost:3001\"</span><span class=\"token punctuation\">,</span>\n   websiteDomain<span class=\"token operator\">:</span> <span class=\"token string\">\"http://localhost:3000\"</span><span class=\"token punctuation\">,</span>\n <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n recipeList<span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span>\n   ThirdPartyEmailPassword<span class=\"token punctuation\">.</span><span class=\"token function\">init</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>\n     signInAndUpFeature<span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n       providers<span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span>\n         Github<span class=\"token punctuation\">.</span><span class=\"token function\">init</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n         Google<span class=\"token punctuation\">.</span><span class=\"token function\">init</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n         Apple<span class=\"token punctuation\">.</span><span class=\"token function\">init</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n       <span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n     <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n   <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n   Session<span class=\"token punctuation\">.</span><span class=\"token function\">init</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n <span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">App</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n\t<span class=\"token comment\">// Your App Code</span>\n <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">default</span> App<span class=\"token punctuation\">;</span></code></pre></div>\n<p>The SuperToken <code class=\"language-text\">init</code> function requires two objects:</p>\n<p><code class=\"language-text\">appInfo</code>: The object that holds application details and domain configuration. At a minimum, it consists of three variables.</p>\n<ul>\n<li><code class=\"language-text\">appName</code>: The name of the application we are building, in our case, let’s set it to “My Demo App”.</li>\n<li><code class=\"language-text\">apiDomain</code>: API domain refers to the domain address of the API server, which we will be configuring in the further sections on ExpressJS. For now, let’s set it to <a href=\"http://localhost:3001\" target=\"_blank\" rel=\"nofollow\">http://localhost:3001</a>.</li>\n<li><code class=\"language-text\">websiteDomain</code>: Domain address of the frontend - application, which is essentially our react server, so in this case, it will be <code class=\"language-text\">http://localhost:3000</code>.</li>\n</ul>\n<p><code class=\"language-text\">recipeList</code>: This object lets us configure the login and session management modules.</p>\n<p>In the recipeList object, as we can see, we had initialised three social providers inside the provider’s list, which are GitHub, Google and Apple. You can also add a custom provider which SuperTokens hasn’t implemented (see <a href=\"https://supertokens.com/docs/thirdpartyemailpassword/common-customizations/signup-form/custom-providers\" target=\"_blank\" rel=\"nofollow\">this page</a>)</p>\n<p><code class=\"language-text\">Session.init()</code> provides the session management feature. This recipe manages the session tokens issued by the backend and also provides the logout functionality.</p>\n<h2 id=\"showing-the-login-ui\" style=\"position:relative;\"><a href=\"#showing-the-login-ui\" aria-label=\"showing the login 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>Showing the login UI</h2>\n<p>This section will guide you on setting up the frontend UI provided by SuperTokens. Since there are several pages (sign in, reset the password, email verification..), SuperTokens needs to manage routing within your frontend app. For that, we have provided integration with react-router-dom:</p>\n<div\n              class=\"gatsby-code-button-container\"\n              data-toaster-id=\"34666877883398685000\"\n              data-toaster-class=\"gatsby-code-button-toaster\"\n              data-toaster-text-class=\"gatsby-code-button-toaster-text\"\n              data-toaster-text=\"Copied!\"\n              data-toaster-duration=\"3500\"\n              onClick=\"copyToClipboard(`yarn add react-router-dom`, `34666877883398685000`)\"\n            >\n              <div\n                class=\"gatsby-code-button\"\n                data-tooltip=\"\"\n              >\n                <svg class=\"gatsby-code-button-icon\" xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\"><path fill=\"none\" d=\"M0 0h24v24H0V0z\"/><path d=\"M16 1H2v16h2V3h12V1zm-1 4l6 6v12H6V5h9zm-1 7h5.5L14 6.5V12z\"/></svg>\n              </div>\n            </div>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token function\">yarn</span> <span class=\"token function\">add</span> react-router-dom</code></pre></div>\n<blockquote>\nNote: In this tutorial, we will be using react-router-dom v>=6, in case if you’re using a different version, the configuration needs to be updated. Read more information here. \n</blockquote>\n<p>Integrating React Router DOM into our app requires a small boilerplate code to set up the history and navigation. For this, we provide a route configuration object for each of our routes. To do this, open the <code class=\"language-text\">App.js</code> file, and update the code to the following:</p>\n<div\n              class=\"gatsby-code-button-container\"\n              data-toaster-id=\"82566399729787850000\"\n              data-toaster-class=\"gatsby-code-button-toaster\"\n              data-toaster-text-class=\"gatsby-code-button-toaster-text\"\n              data-toaster-text=\"Copied!\"\n              data-toaster-duration=\"3500\"\n              onClick=\"copyToClipboard(`//my-demo-app/src/App.js\n\nimport ThirdPartyEmailPassword, {\n Github,\n Google,\n Apple,\n} from &quot;supertokens-auth-react/recipe/thirdpartyemailpassword&quot;;\nimport Session from &quot;supertokens-auth-react/recipe/session&quot;;\n\n// import react-router-dom components\n\nimport { Routes, BrowserRouter as Router, Route } from &quot;react-router-dom&quot;;\n\n// import SuperTokens Auth routes\n\nimport SuperTokens, {\n getSuperTokensRoutesForReactRouterDom,\n} from &quot;supertokens-auth-react&quot;;\n\nimport Home from &quot;./Home&quot;;\n\n\nSuperTokens.init({\n\t...\n});\n\n\nfunction App() {\n return (\n   <div className=&quot;App&quot;>\n     <Router>\n       <Routes>\n         {/*This renders the login UI on the /auth route*/}\n         {getSuperTokensRoutesForReactRouterDom(require(&quot;react-router-dom&quot;))}\n\n         <Route path=&quot;/&quot; element={<Home />} />\n\n       </Routes>\n     </Router>\n   </div>\n );\n}`, `82566399729787850000`)\"\n            >\n              <div\n                class=\"gatsby-code-button\"\n                data-tooltip=\"\"\n              >\n                <svg class=\"gatsby-code-button-icon\" xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\"><path fill=\"none\" d=\"M0 0h24v24H0V0z\"/><path d=\"M16 1H2v16h2V3h12V1zm-1 4l6 6v12H6V5h9zm-1 7h5.5L14 6.5V12z\"/></svg>\n              </div>\n            </div>\n<div class=\"gatsby-highlight\" data-language=\"tsx\"><pre class=\"language-tsx\"><code class=\"language-tsx\"><span class=\"token comment\">//my-demo-app/src/App.js</span>\n\n<span class=\"token keyword\">import</span> ThirdPartyEmailPassword<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span>\n Github<span class=\"token punctuation\">,</span>\n Google<span class=\"token punctuation\">,</span>\n Apple<span class=\"token punctuation\">,</span>\n<span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">\"supertokens-auth-react/recipe/thirdpartyemailpassword\"</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">import</span> Session <span class=\"token keyword\">from</span> <span class=\"token string\">\"supertokens-auth-react/recipe/session\"</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">// import react-router-dom components</span>\n\n<span class=\"token keyword\">import</span> <span class=\"token punctuation\">{</span> Routes<span class=\"token punctuation\">,</span> BrowserRouter <span class=\"token keyword\">as</span> Router<span class=\"token punctuation\">,</span> Route <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">\"react-router-dom\"</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">// import SuperTokens Auth routes</span>\n\n<span class=\"token keyword\">import</span> SuperTokens<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span>\n getSuperTokensRoutesForReactRouterDom<span class=\"token punctuation\">,</span>\n<span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">\"supertokens-auth-react\"</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">import</span> Home <span class=\"token keyword\">from</span> <span class=\"token string\">\"./Home\"</span><span class=\"token punctuation\">;</span>\n\n\nSuperTokens<span class=\"token punctuation\">.</span><span class=\"token function\">init</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>\n\t<span class=\"token operator\">...</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">App</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n   <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>div</span> <span class=\"token attr-name\">className</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>App<span class=\"token punctuation\">\"</span></span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n     </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span><span class=\"token class-name\">Router</span></span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n       </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span><span class=\"token class-name\">Routes</span></span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n         </span><span class=\"token punctuation\">{</span><span class=\"token comment\">/*This renders the login UI on the /auth route*/</span><span class=\"token punctuation\">}</span><span class=\"token plain-text\">\n         </span><span class=\"token punctuation\">{</span><span class=\"token function\">getSuperTokensRoutesForReactRouterDom</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">require</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"react-router-dom\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span><span class=\"token plain-text\">\n\n         </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span><span class=\"token class-name\">Route</span></span> <span class=\"token attr-name\">path</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>/<span class=\"token punctuation\">\"</span></span> <span class=\"token attr-name\">element</span><span class=\"token script language-javascript\"><span class=\"token script-punctuation punctuation\">=</span><span class=\"token punctuation\">{</span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span><span class=\"token class-name\">Home</span></span> <span class=\"token punctuation\">/></span></span><span class=\"token punctuation\">}</span></span> <span class=\"token punctuation\">/></span></span><span class=\"token plain-text\">\n\n       </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span><span class=\"token class-name\">Routes</span></span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n     </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span><span class=\"token class-name\">Router</span></span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n   </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>div</span><span class=\"token punctuation\">></span></span>\n <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>Here, we added the Router configuration with a special function <code class=\"language-text\">getSuperTokensRoutesForReactRouterDom</code>, which configures all the auth routes provided by SuperTokens. By default, this function will catch all navigation to <code class=\"language-text\">/auth/*</code> and display relevant authentication UI based on the path.</p>\n<p>Note that, here we are using a simple Home component for the <code class=\"language-text\">/route</code> path, hence, let’s create a new Home component inside the <code class=\"language-text\">src</code> folder:</p>\n<div\n              class=\"gatsby-code-button-container\"\n              data-toaster-id=\"81798355026493180000\"\n              data-toaster-class=\"gatsby-code-button-toaster\"\n              data-toaster-text-class=\"gatsby-code-button-toaster-text\"\n              data-toaster-text=\"Copied!\"\n              data-toaster-duration=\"3500\"\n              onClick=\"copyToClipboard(`touch src/Home/index.js`, `81798355026493180000`)\"\n            >\n              <div\n                class=\"gatsby-code-button\"\n                data-tooltip=\"\"\n              >\n                <svg class=\"gatsby-code-button-icon\" xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\"><path fill=\"none\" d=\"M0 0h24v24H0V0z\"/><path d=\"M16 1H2v16h2V3h12V1zm-1 4l6 6v12H6V5h9zm-1 7h5.5L14 6.5V12z\"/></svg>\n              </div>\n            </div>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token function\">touch</span> src/Home/index.js</code></pre></div>\n<div\n              class=\"gatsby-code-button-container\"\n              data-toaster-id=\"53405839694077665000\"\n              data-toaster-class=\"gatsby-code-button-toaster\"\n              data-toaster-text-class=\"gatsby-code-button-toaster-text\"\n              data-toaster-text=\"Copied!\"\n              data-toaster-duration=\"3500\"\n              onClick=\"copyToClipboard(`\nexport default function Home() {\n return (\n   <>\n     <h1>Hello from SuperTokens</h1>\n   </>\n );\n}`, `53405839694077665000`)\"\n            >\n              <div\n                class=\"gatsby-code-button\"\n                data-tooltip=\"\"\n              >\n                <svg class=\"gatsby-code-button-icon\" xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\"><path fill=\"none\" d=\"M0 0h24v24H0V0z\"/><path d=\"M16 1H2v16h2V3h12V1zm-1 4l6 6v12H6V5h9zm-1 7h5.5L14 6.5V12z\"/></svg>\n              </div>\n            </div>\n<div class=\"gatsby-highlight\" data-language=\"tsx\"><pre class=\"language-tsx\"><code class=\"language-tsx\">\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">default</span> <span class=\"token keyword\">function</span> <span class=\"token function\">Home</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n   <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span></span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n     </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>h1</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">Hello from SuperTokens</span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>h1</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n   </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span></span><span class=\"token punctuation\">></span></span>\n <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>To see the auth UI in action, run the server and navigate to <code class=\"language-text\">http://localhost:3000/auth</code>.</p>\n<div\n              class=\"gatsby-code-button-container\"\n              data-toaster-id=\"4964284105900952000\"\n              data-toaster-class=\"gatsby-code-button-toaster\"\n              data-toaster-text-class=\"gatsby-code-button-toaster-text\"\n              data-toaster-text=\"Copied!\"\n              data-toaster-duration=\"3500\"\n              onClick=\"copyToClipboard(`yarn start`, `4964284105900952000`)\"\n            >\n              <div\n                class=\"gatsby-code-button\"\n                data-tooltip=\"\"\n              >\n                <svg class=\"gatsby-code-button-icon\" xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\"><path fill=\"none\" d=\"M0 0h24v24H0V0z\"/><path d=\"M16 1H2v16h2V3h12V1zm-1 4l6 6v12H6V5h9zm-1 7h5.5L14 6.5V12z\"/></svg>\n              </div>\n            </div>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token function\">yarn</span> start</code></pre></div>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 630px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/49843ddd3ea434f4798199522b671116/29007/emailpasswordimage.png\"\n    style=\"display: block\"\n    target=\"_blank\"\n    rel=\"noopener\"\n  >\n    <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 67.08860759493672%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAANCAIAAAAmMtkJAAAACXBIWXMAAAsTAAALEwEAmpwYAAACYElEQVQoz32QXUiTURjHn5C0iKAPyQuJMkr6gMiim8LY2weFlDLZhWXSLiq6aRF+0cqWF7U1N3RmfpXiTJ1OAksjokxvwtUkkdKWWVh610Vue9+9533fc84T70qRBT384XB4nh+/5xwoXW33ZN1vy/f2mB48tQ31tfzsvfejp3au2zPr93zz10z7PdM9nq8+V8jn/NRROeotHWwvf1VxpP5Cxm0wQ8Uz52tENi9FCSUKlSUiinI0IoWjsUg0FolIYVEWJSKJsjhPwr/EcESRXjQOWzbaoQCs/c5hRNSIxilHjojImX7EJInIZPEabyBTGSK+aR25uaUKcqH8sW5GqjFcKI3SiakvYxOTH0JT46HPqqouthjVx0a9AXemC07p8FACrMqxgVvWJ9biAdu1PmsxEaN/vQvw+KNA/XY3CFDS+49ZJUp3davX0djhbmmzN8REKcE80fG2JbMG9sPV9rsv4zBdnKCUSgrRkGvIKSLjPAGebA96M+phB5hbHc/1dy6FGQtLqsqRoh6+FI4vGGp7/zCtGdLhRKOjNwHmVFW/B9jcu3iCnKoJ8Mfm8aqVzZAGR+vu+BCRyArVaDxMUwibCyozI8pMgM4GKVEYRU45p1wjumOkZqwcamEtHKhzdCWY/1N//nWwOmCCMli3bM++rTnG4xfzDJfyhStGwWIULCahpEC4fkawnTZUXj7sasrp7Mz1+/L83Xl+78kuV26TeeeN7OTzkLZ875qkXSmwLQUyV8Hu9XAoFQypYNgAx9LBtBnOboKibLBUJNfaVzRYk91FSWUH4VxWUmFWSuFvdElLgSCiJ8kAAAAASUVORK5CYII='); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"email password UI\"\n        title=\"email password UI\"\n        src=\"/static/49843ddd3ea434f4798199522b671116/f058b/emailpasswordimage.png\"\n        srcset=\"/static/49843ddd3ea434f4798199522b671116/c26ae/emailpasswordimage.png 158w,\n/static/49843ddd3ea434f4798199522b671116/6bdcf/emailpasswordimage.png 315w,\n/static/49843ddd3ea434f4798199522b671116/f058b/emailpasswordimage.png 630w,\n/static/49843ddd3ea434f4798199522b671116/40601/emailpasswordimage.png 945w,\n/static/49843ddd3ea434f4798199522b671116/78612/emailpasswordimage.png 1260w,\n/static/49843ddd3ea434f4798199522b671116/29007/emailpasswordimage.png 1600w\"\n        sizes=\"(max-width: 630px) 100vw, 630px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n        decoding=\"async\"\n      />\n  </a>\n    </span></p>\n<p>And, just like that, in under 2 mins, we had set up the front-end for adding authentication to react project, thanks to SuperTokens! Clicking on the Forgot password button will navigate the user to the forgot password form and also change the website URL path.</p>\n<h3 id=\"setting-up-an-expressjs-project-for-backend\" style=\"position:relative;\"><a href=\"#setting-up-an-expressjs-project-for-backend\" aria-label=\"setting up an expressjs project for backend 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 an ExpressJS Project for Backend</h3>\n<p>This application will use express JS and supertokens-node SDK on the backend. The node SDK will automatically expose all the authentication routes required by the frontend UI. To do this, create a new directory next to the my-demo-app. Name this directory as <code class=\"language-text\">demo-app-backend</code>, and install express using npm.</p>\n<div\n              class=\"gatsby-code-button-container\"\n              data-toaster-id=\"39642857082342060000\"\n              data-toaster-class=\"gatsby-code-button-toaster\"\n              data-toaster-text-class=\"gatsby-code-button-toaster-text\"\n              data-toaster-text=\"Copied!\"\n              data-toaster-duration=\"3500\"\n              onClick=\"copyToClipboard(`mkdir demo-app-backend\ncd demo-app-backend\nnpm install express`, `39642857082342060000`)\"\n            >\n              <div\n                class=\"gatsby-code-button\"\n                data-tooltip=\"\"\n              >\n                <svg class=\"gatsby-code-button-icon\" xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\"><path fill=\"none\" d=\"M0 0h24v24H0V0z\"/><path d=\"M16 1H2v16h2V3h12V1zm-1 4l6 6v12H6V5h9zm-1 7h5.5L14 6.5V12z\"/></svg>\n              </div>\n            </div>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token function\">mkdir</span> demo-app-backend\n<span class=\"token builtin class-name\">cd</span> demo-app-backend\n<span class=\"token function\">npm</span> <span class=\"token function\">install</span> express</code></pre></div>\n<p>Next, let’s create a new file to implement all the APIs.</p>\n<div\n              class=\"gatsby-code-button-container\"\n              data-toaster-id=\"74101350664938240000\"\n              data-toaster-class=\"gatsby-code-button-toaster\"\n              data-toaster-text-class=\"gatsby-code-button-toaster-text\"\n              data-toaster-text=\"Copied!\"\n              data-toaster-duration=\"3500\"\n              onClick=\"copyToClipboard(`touch api-server.js`, `74101350664938240000`)\"\n            >\n              <div\n                class=\"gatsby-code-button\"\n                data-tooltip=\"\"\n              >\n                <svg class=\"gatsby-code-button-icon\" xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\"><path fill=\"none\" d=\"M0 0h24v24H0V0z\"/><path d=\"M16 1H2v16h2V3h12V1zm-1 4l6 6v12H6V5h9zm-1 7h5.5L14 6.5V12z\"/></svg>\n              </div>\n            </div>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token function\">touch</span> api-server.js</code></pre></div>\n<p>Initially, update the contents of the server file to the following to set up a basic server:</p>\n<div\n              class=\"gatsby-code-button-container\"\n              data-toaster-id=\"30467088017369570000\"\n              data-toaster-class=\"gatsby-code-button-toaster\"\n              data-toaster-text-class=\"gatsby-code-button-toaster-text\"\n              data-toaster-text=\"Copied!\"\n              data-toaster-duration=\"3500\"\n              onClick=\"copyToClipboard(`# demo-app-backend/server.js\n\nconst express = require(&quot;express&quot;);\nconst app = express();\nconst port = 3001;\n\napp.get(&quot;/&quot;, (req, res) => {\n res.send(&quot;Hello World!&quot;);\n});\n\napp.listen(port, () => {\n console.log(\\`Example app listening at http://localhost:\\${port}\\`);\n});`, `30467088017369570000`)\"\n            >\n              <div\n                class=\"gatsby-code-button\"\n                data-tooltip=\"\"\n              >\n                <svg class=\"gatsby-code-button-icon\" xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\"><path fill=\"none\" d=\"M0 0h24v24H0V0z\"/><path d=\"M16 1H2v16h2V3h12V1zm-1 4l6 6v12H6V5h9zm-1 7h5.5L14 6.5V12z\"/></svg>\n              </div>\n            </div>\n<div class=\"gatsby-highlight\" data-language=\"tsx\"><pre class=\"language-tsx\"><code class=\"language-tsx\"># demo<span class=\"token operator\">-</span>app<span class=\"token operator\">-</span>backend<span class=\"token operator\">/</span>server<span class=\"token punctuation\">.</span>js\n\n<span class=\"token keyword\">const</span> express <span class=\"token operator\">=</span> <span class=\"token keyword\">require</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"express\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> app <span class=\"token operator\">=</span> <span class=\"token function\">express</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> port <span class=\"token operator\">=</span> <span class=\"token number\">3001</span><span class=\"token punctuation\">;</span>\n\napp<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"/\"</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span>req<span class=\"token punctuation\">,</span> res<span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n res<span class=\"token punctuation\">.</span><span class=\"token function\">send</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Hello World!\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\napp<span class=\"token punctuation\">.</span><span class=\"token function\">listen</span><span class=\"token punctuation\">(</span>port<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n <span class=\"token builtin\">console</span><span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">Example app listening at http://localhost:</span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>port<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Install the supertokens-node package, and update the server file to the following:</p>\n<div\n              class=\"gatsby-code-button-container\"\n              data-toaster-id=\"27880450667389202000\"\n              data-toaster-class=\"gatsby-code-button-toaster\"\n              data-toaster-text-class=\"gatsby-code-button-toaster-text\"\n              data-toaster-text=\"Copied!\"\n              data-toaster-duration=\"3500\"\n              onClick=\"copyToClipboard(`npm i -s supertokens-node`, `27880450667389202000`)\"\n            >\n              <div\n                class=\"gatsby-code-button\"\n                data-tooltip=\"\"\n              >\n                <svg class=\"gatsby-code-button-icon\" xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\"><path fill=\"none\" d=\"M0 0h24v24H0V0z\"/><path d=\"M16 1H2v16h2V3h12V1zm-1 4l6 6v12H6V5h9zm-1 7h5.5L14 6.5V12z\"/></svg>\n              </div>\n            </div>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token function\">npm</span> i -s supertokens-node</code></pre></div>\n<div\n              class=\"gatsby-code-button-container\"\n              data-toaster-id=\"94307100577190500000\"\n              data-toaster-class=\"gatsby-code-button-toaster\"\n              data-toaster-text-class=\"gatsby-code-button-toaster-text\"\n              data-toaster-text=\"Copied!\"\n              data-toaster-duration=\"3500\"\n              onClick=\"copyToClipboard(`# demo-app-backend/server.js\n\nconst express = require(&quot;express&quot;);\n\nlet supertokens = require(&quot;supertokens-node&quot;);\nlet Session = require(&quot;supertokens-node/recipe/session&quot;);\nlet ThirdPartyEmailPassword = require(&quot;supertokens-node/recipe/thirdpartyemailpassword&quot;);\n\nconst app = express();\nconst port = 3001;\n\nsupertokens.init({\n framework: &quot;express&quot;,\n supertokens: {\n   connectionURI:\n     &quot;https://try.superotkens.io&quot;,\n },\n appInfo: {\n\n   // learn more about this on\n   //https://supertokens.com/docs/thirdpartyemailpassword/appinfo\n\n   appName: &quot;My Demo App&quot;,\n   apiDomain: &quot;http://localhost:3001&quot;,\n   websiteDomain: &quot;http://localhost:3000&quot;,\n },\n recipeList: [\n   ThirdPartyEmailPassword.init({\n     /*TODO: See next step*/\n   }),\n   Session.init(), // initializes session features\n ],\n});\n\napp.get(&quot;/&quot;, (req, res) => {\n res.send(&quot;Hello World!&quot;);\n});\n\napp.listen(port, () => {\n console.log(\\`Example app listening at http://localhost:\\${port}\\`);\n});`, `94307100577190500000`)\"\n            >\n              <div\n                class=\"gatsby-code-button\"\n                data-tooltip=\"\"\n              >\n                <svg class=\"gatsby-code-button-icon\" xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\"><path fill=\"none\" d=\"M0 0h24v24H0V0z\"/><path d=\"M16 1H2v16h2V3h12V1zm-1 4l6 6v12H6V5h9zm-1 7h5.5L14 6.5V12z\"/></svg>\n              </div>\n            </div>\n<div class=\"gatsby-highlight\" data-language=\"tsx\"><pre class=\"language-tsx\"><code class=\"language-tsx\"># demo<span class=\"token operator\">-</span>app<span class=\"token operator\">-</span>backend<span class=\"token operator\">/</span>server<span class=\"token punctuation\">.</span>js\n\n<span class=\"token keyword\">const</span> express <span class=\"token operator\">=</span> <span class=\"token keyword\">require</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"express\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">let</span> supertokens <span class=\"token operator\">=</span> <span class=\"token keyword\">require</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"supertokens-node\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">let</span> Session <span class=\"token operator\">=</span> <span class=\"token keyword\">require</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"supertokens-node/recipe/session\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">let</span> ThirdPartyEmailPassword <span class=\"token operator\">=</span> <span class=\"token keyword\">require</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"supertokens-node/recipe/thirdpartyemailpassword\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> app <span class=\"token operator\">=</span> <span class=\"token function\">express</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> port <span class=\"token operator\">=</span> <span class=\"token number\">3001</span><span class=\"token punctuation\">;</span>\n\nsupertokens<span class=\"token punctuation\">.</span><span class=\"token function\">init</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>\n framework<span class=\"token operator\">:</span> <span class=\"token string\">\"express\"</span><span class=\"token punctuation\">,</span>\n supertokens<span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n   connectionURI<span class=\"token operator\">:</span>\n     <span class=\"token string\">\"https://try.superotkens.io\"</span><span class=\"token punctuation\">,</span>\n <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n appInfo<span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n\n   <span class=\"token comment\">// learn more about this on</span>\n   <span class=\"token comment\">//https://supertokens.com/docs/thirdpartyemailpassword/appinfo</span>\n\n   appName<span class=\"token operator\">:</span> <span class=\"token string\">\"My Demo App\"</span><span class=\"token punctuation\">,</span>\n   apiDomain<span class=\"token operator\">:</span> <span class=\"token string\">\"http://localhost:3001\"</span><span class=\"token punctuation\">,</span>\n   websiteDomain<span class=\"token operator\">:</span> <span class=\"token string\">\"http://localhost:3000\"</span><span class=\"token punctuation\">,</span>\n <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n recipeList<span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span>\n   ThirdPartyEmailPassword<span class=\"token punctuation\">.</span><span class=\"token function\">init</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>\n     <span class=\"token comment\">/*TODO: See next step*/</span>\n   <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n   Session<span class=\"token punctuation\">.</span><span class=\"token function\">init</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token comment\">// initializes session features</span>\n <span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\napp<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"/\"</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span>req<span class=\"token punctuation\">,</span> res<span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n res<span class=\"token punctuation\">.</span><span class=\"token function\">send</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Hello World!\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\napp<span class=\"token punctuation\">.</span><span class=\"token function\">listen</span><span class=\"token punctuation\">(</span>port<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n <span class=\"token builtin\">console</span><span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">Example app listening at http://localhost:</span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>port<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>In the above code snippet, we first import the necessary modules from the supertokens-node package. Next, we initialize the supertokens function, which primarily uses three objects:</p>\n<ul>\n<li><code class=\"language-text\">framework</code>: The type of backend framework that APIs are configured to, in our case <code class=\"language-text\">express</code>.</li>\n<li><code class=\"language-text\">supertokens</code>: The supertokens object tells us where to find the supertokens core. The URI, <code class=\"language-text\">https://try.supertokens.com</code> that’s mentioned on the code snippet is a demo SuperTokens core server that you can use for getting started quickly. Later on, you should update this to point to a core dedicated to your application - either by signing up on <a href=\"https://supertokens.com\" target=\"_blank\" rel=\"nofollow\">supertokens.com</a> or running a self-hosted version of the core.</li>\n<li><code class=\"language-text\">appInfo</code>: Similar to the appInfo object that we used on the frontend app, this object takes in all the application information.</li>\n<li><code class=\"language-text\">recipeList</code>: We have the recipe List on the backend as well,  where we can configure the ​​type of authentication we need.  In our case, we will add the <code class=\"language-text\">ThirdPartyEmailPassword</code> and the <code class=\"language-text\">Session</code> recipe.</li>\n</ul>\n<h3 id=\"configuring-and-initialising-social-login-providers\" style=\"position:relative;\"><a href=\"#configuring-and-initialising-social-login-providers\" aria-label=\"configuring and initialising social login 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>Configuring and Initialising Social Login Providers</h3>\n<p>The next step is to tell the <code class=\"language-text\">ThirdPartyEmailPassword</code> recipe about the social login providers we want and give it the necessary credentials.</p>\n<blockquote>\nOn our front-end, we had configured GitHub, Google, and Apple as our social providers. We’ll need to update the `recipeList` object with their social OAuth keys. \n</blockquote>\n<p>Update the code on <code class=\"language-text\">server.js</code> to the following:</p>\n<div\n              class=\"gatsby-code-button-container\"\n              data-toaster-id=\"94432250017035240000\"\n              data-toaster-class=\"gatsby-code-button-toaster\"\n              data-toaster-text-class=\"gatsby-code-button-toaster-text\"\n              data-toaster-text=\"Copied!\"\n              data-toaster-duration=\"3500\"\n              onClick=\"copyToClipboard(`# demo-app-backend/server.js\n\nlet {Google, Github, Apple} = ThirdPartyEmailPassword;\n\nsupertokens.init({\n framework: &quot;express&quot;,\n supertokens: {\n   // These are the connection details of the app you created on supertokens.com\n   connectionURI:\n     &quot;Update connection URI here&quot;,\n },\n appInfo: {\n   // learn more about this on https://supertokens.com/docs/thirdpartyemailpassword/appinfo\n   appName: &quot;My Demo App&quot;,\n   apiDomain: &quot;http://localhost:3001&quot;,\n   websiteDomain: &quot;http://localhost:3000&quot;,\n },\n recipeList: [\n   ThirdPartyEmailPassword.init({\n     providers: [\n       Google({\n         clientId: &quot;&quot;,\n         clientSecret: &quot;&quot;,\n       }),\n       Github({\n         clientId: &quot;&quot;,\n         clientSecret: &quot;&quot;,\n       }),\n       Apple({\n         clientId: &quot;&quot;,\n         clientSecret: {\n           keyId: &quot;&quot;,\n           privateKey: &quot;&quot;,\n           teamId: &quot;&quot;,\n         },\n       }),\n     ],\n   }),\n   Session.init(), // initializes session features\n ],\n});`, `94432250017035240000`)\"\n            >\n              <div\n                class=\"gatsby-code-button\"\n                data-tooltip=\"\"\n              >\n                <svg class=\"gatsby-code-button-icon\" xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\"><path fill=\"none\" d=\"M0 0h24v24H0V0z\"/><path d=\"M16 1H2v16h2V3h12V1zm-1 4l6 6v12H6V5h9zm-1 7h5.5L14 6.5V12z\"/></svg>\n              </div>\n            </div>\n<div class=\"gatsby-highlight\" data-language=\"tsx\"><pre class=\"language-tsx\"><code class=\"language-tsx\"># demo<span class=\"token operator\">-</span>app<span class=\"token operator\">-</span>backend<span class=\"token operator\">/</span>server<span class=\"token punctuation\">.</span>js\n\n<span class=\"token keyword\">let</span> <span class=\"token punctuation\">{</span>Google<span class=\"token punctuation\">,</span> Github<span class=\"token punctuation\">,</span> Apple<span class=\"token punctuation\">}</span> <span class=\"token operator\">=</span> ThirdPartyEmailPassword<span class=\"token punctuation\">;</span>\n\nsupertokens<span class=\"token punctuation\">.</span><span class=\"token function\">init</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>\n framework<span class=\"token operator\">:</span> <span class=\"token string\">\"express\"</span><span class=\"token punctuation\">,</span>\n supertokens<span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n   <span class=\"token comment\">// These are the connection details of the app you created on supertokens.com</span>\n   connectionURI<span class=\"token operator\">:</span>\n     <span class=\"token string\">\"Update connection URI here\"</span><span class=\"token punctuation\">,</span>\n <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n appInfo<span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n   <span class=\"token comment\">// learn more about this on https://supertokens.com/docs/thirdpartyemailpassword/appinfo</span>\n   appName<span class=\"token operator\">:</span> <span class=\"token string\">\"My Demo App\"</span><span class=\"token punctuation\">,</span>\n   apiDomain<span class=\"token operator\">:</span> <span class=\"token string\">\"http://localhost:3001\"</span><span class=\"token punctuation\">,</span>\n   websiteDomain<span class=\"token operator\">:</span> <span class=\"token string\">\"http://localhost:3000\"</span><span class=\"token punctuation\">,</span>\n <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n recipeList<span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span>\n   ThirdPartyEmailPassword<span class=\"token punctuation\">.</span><span class=\"token function\">init</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>\n     providers<span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span>\n       <span class=\"token function\">Google</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>\n         clientId<span class=\"token operator\">:</span> <span class=\"token string\">\"\"</span><span class=\"token punctuation\">,</span>\n         clientSecret<span class=\"token operator\">:</span> <span class=\"token string\">\"\"</span><span class=\"token punctuation\">,</span>\n       <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n       <span class=\"token function\">Github</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>\n         clientId<span class=\"token operator\">:</span> <span class=\"token string\">\"\"</span><span class=\"token punctuation\">,</span>\n         clientSecret<span class=\"token operator\">:</span> <span class=\"token string\">\"\"</span><span class=\"token punctuation\">,</span>\n       <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n       <span class=\"token function\">Apple</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>\n         clientId<span class=\"token operator\">:</span> <span class=\"token string\">\"\"</span><span class=\"token punctuation\">,</span>\n         clientSecret<span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n           keyId<span class=\"token operator\">:</span> <span class=\"token string\">\"\"</span><span class=\"token punctuation\">,</span>\n           privateKey<span class=\"token operator\">:</span> <span class=\"token string\">\"\"</span><span class=\"token punctuation\">,</span>\n           teamId<span class=\"token operator\">:</span> <span class=\"token string\">\"\"</span><span class=\"token punctuation\">,</span>\n         <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n       <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n     <span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n   <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n   Session<span class=\"token punctuation\">.</span><span class=\"token function\">init</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token comment\">// initializes session features</span>\n <span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><strong>Note</strong>: To obtain Google, GitHub, Apple Oauth keys, refer to their documentation <a href=\"https://developers.google.com/identity/protocols/oauth2\" target=\"_blank\" rel=\"nofollow\">here</a>, <a href=\"https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens\" target=\"_blank\" rel=\"nofollow\">here</a> and <a href=\"https://developer.apple.com/documentation/sign_in_with_apple/generate_and_validate_tokens\" target=\"_blank\" rel=\"nofollow\">here</a> respectively. SuperTokens also provides us with a few test keys for testing the configuration, you can find them in the backend configuration from the documentation <a href=\"https://supertokens.com/docs/thirdpartyemailpassword/pre-built-ui/setup/backend\" target=\"_blank\" rel=\"nofollow\">here</a>.</p>\n<h2 id=\"supertokens-apis--cors-setup\" style=\"position:relative;\"><a href=\"#supertokens-apis--cors-setup\" aria-label=\"supertokens apis  cors setup 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>SuperTokens APIs &#x26; CORS Setup</h2>\n<p>The next step is to expose all the APIs that the frontend can call. Some of these APIs are sign-up, sign-in, signout, and session refreshing. We will also need to set up CORS to whitelist requests to your API server to allow resource sharing and headers from different locations. Let’s start by adding a cors package to the application:</p>\n<div\n              class=\"gatsby-code-button-container\"\n              data-toaster-id=\"13924445373323667000\"\n              data-toaster-class=\"gatsby-code-button-toaster\"\n              data-toaster-text-class=\"gatsby-code-button-toaster-text\"\n              data-toaster-text=\"Copied!\"\n              data-toaster-duration=\"3500\"\n              onClick=\"copyToClipboard(`npm install cors`, `13924445373323667000`)\"\n            >\n              <div\n                class=\"gatsby-code-button\"\n                data-tooltip=\"\"\n              >\n                <svg class=\"gatsby-code-button-icon\" xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\"><path fill=\"none\" d=\"M0 0h24v24H0V0z\"/><path d=\"M16 1H2v16h2V3h12V1zm-1 4l6 6v12H6V5h9zm-1 7h5.5L14 6.5V12z\"/></svg>\n              </div>\n            </div>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token function\">npm</span> <span class=\"token function\">install</span> cors</code></pre></div>\n<p>Next, update the <code class=\"language-text\">server.js</code> file to the following:</p>\n<div\n              class=\"gatsby-code-button-container\"\n              data-toaster-id=\"94017912573580660000\"\n              data-toaster-class=\"gatsby-code-button-toaster\"\n              data-toaster-text-class=\"gatsby-code-button-toaster-text\"\n              data-toaster-text=\"Copied!\"\n              data-toaster-duration=\"3500\"\n              onClick=\"copyToClipboard(`let cors = require(&quot;cors&quot;);\n\nlet { middleware } = require(&quot;supertokens-node/framework/express&quot;);\nsupertokens.init({\n...\n ],\n});\n\napp.use(\n cors({\n   origin: &quot;http://localhost:3000&quot;,\n   allowedHeaders: [\n    &quot;content-type&quot;,\n    ...supertokens.getAllCORSHeaders()],\n   credentials: true,\n })\n);\n\napp.use(middleware());`, `94017912573580660000`)\"\n            >\n              <div\n                class=\"gatsby-code-button\"\n                data-tooltip=\"\"\n              >\n                <svg class=\"gatsby-code-button-icon\" xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\"><path fill=\"none\" d=\"M0 0h24v24H0V0z\"/><path d=\"M16 1H2v16h2V3h12V1zm-1 4l6 6v12H6V5h9zm-1 7h5.5L14 6.5V12z\"/></svg>\n              </div>\n            </div>\n<div class=\"gatsby-highlight\" data-language=\"tsx\"><pre class=\"language-tsx\"><code class=\"language-tsx\"><span class=\"token keyword\">let</span> cors <span class=\"token operator\">=</span> <span class=\"token keyword\">require</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"cors\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">let</span> <span class=\"token punctuation\">{</span> middleware <span class=\"token punctuation\">}</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">require</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"supertokens-node/framework/express\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nsupertokens<span class=\"token punctuation\">.</span><span class=\"token function\">init</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>\n<span class=\"token operator\">...</span>\n <span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\napp<span class=\"token punctuation\">.</span><span class=\"token function\">use</span><span class=\"token punctuation\">(</span>\n <span class=\"token function\">cors</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>\n   origin<span class=\"token operator\">:</span> <span class=\"token string\">\"http://localhost:3000\"</span><span class=\"token punctuation\">,</span>\n   allowedHeaders<span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span>\n    <span class=\"token string\">\"content-type\"</span><span class=\"token punctuation\">,</span>\n    <span class=\"token operator\">...</span>supertokens<span class=\"token punctuation\">.</span><span class=\"token function\">getAllCORSHeaders</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n   credentials<span class=\"token operator\">:</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">,</span>\n <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\napp<span class=\"token punctuation\">.</span><span class=\"token function\">use</span><span class=\"token punctuation\">(</span><span class=\"token function\">middleware</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Above, we first set the CORS to accept requests from the ReactJS app we created earlier. Next, we add all the authentication routes using the SuperToken’s middleware function. Just like that, all our API routes should be configured.</p>\n<p><strong>Adding SuperTokens Error Handler</strong></p>\n<p>Additionally, let’s add the SuperTokens error handler. With this, whenever any of your app’s APIs throws an error that can be handled by SuperTokens (for example session related errors), then the <code class=\"language-text\">errorHandler</code> will take care of handling those.</p>\n<div\n              class=\"gatsby-code-button-container\"\n              data-toaster-id=\"41181584931968570000\"\n              data-toaster-class=\"gatsby-code-button-toaster\"\n              data-toaster-text-class=\"gatsby-code-button-toaster-text\"\n              data-toaster-text=\"Copied!\"\n              data-toaster-duration=\"3500\"\n              onClick=\"copyToClipboard(`let {errorHandler} = require(&quot;supertokens-node/framework/express&quot;);\n// ...your API routes\n\n// Add this AFTER all your routes\napp.use(errorHandler())`, `41181584931968570000`)\"\n            >\n              <div\n                class=\"gatsby-code-button\"\n                data-tooltip=\"\"\n              >\n                <svg class=\"gatsby-code-button-icon\" xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\"><path fill=\"none\" d=\"M0 0h24v24H0V0z\"/><path d=\"M16 1H2v16h2V3h12V1zm-1 4l6 6v12H6V5h9zm-1 7h5.5L14 6.5V12z\"/></svg>\n              </div>\n            </div>\n<div class=\"gatsby-highlight\" data-language=\"tsx\"><pre class=\"language-tsx\"><code class=\"language-tsx\"><span class=\"token keyword\">let</span> <span class=\"token punctuation\">{</span>errorHandler<span class=\"token punctuation\">}</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">require</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"supertokens-node/framework/express\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">// ...your API routes</span>\n\n<span class=\"token comment\">// Add this AFTER all your routes</span>\napp<span class=\"token punctuation\">.</span><span class=\"token function\">use</span><span class=\"token punctuation\">(</span><span class=\"token function\">errorHandler</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h2 id=\"testing-auth-and-accessing-user-information\" style=\"position:relative;\"><a href=\"#testing-auth-and-accessing-user-information\" aria-label=\"testing auth and accessing user information 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>Testing Auth and Accessing User Information</h2>\n<p>Our backend server and the frontend server are now fully configured!  Now, let’s test the authentication by accessing the user information on the frontend and also by implementing logic to log out.</p>\n<p>First, we’ll need to wrap the Home component with the authentication wrapper to protect that route. This means that the user must be logged in to access that page, otherwise, SuperTokens redirects them to the login UI. For this, we’ll be using the <code class=\"language-text\">ThirdPartyEmailPasswordAuth</code> class from supertokens. This is how the <code class=\"language-text\">App.js</code> file looks like now:</p>\n<div\n              class=\"gatsby-code-button-container\"\n              data-toaster-id=\"64920309183292830000\"\n              data-toaster-class=\"gatsby-code-button-toaster\"\n              data-toaster-text-class=\"gatsby-code-button-toaster-text\"\n              data-toaster-text=\"Copied!\"\n              data-toaster-duration=\"3500\"\n              onClick=\"copyToClipboard(`//my-demo-app/src/App.js\n\n// imports\n\nimport ThirdPartyEmailPassword, {\n  ThirdPartyEmailPasswordAuth,\n  Google,\n  Github,\n  Apple,\n} from &quot;supertokens-auth-react/recipe/thirdpartyemailpassword&quot;;\n\nSuperTokens.init({\n…\n});\n\nfunction App() {\n  return (\n    <div className=&quot;App&quot;>\n      <Router>\n        <Routes>\n          {/*This renders the login UI on the /auth route*/}\n          {getSuperTokensRoutesForReactRouterDom(require(&quot;react-router-dom&quot;))}\n          <Route\n            path=&quot;/&quot;\n            element={\n              <ThirdPartyEmailPasswordAuth>\n                <Home />\n              </ThirdPartyEmailPasswordAuth>\n            }\n          />\n        </Routes>\n      </Router>\n    </div>\n  );\n}\n\nexport default App;`, `64920309183292830000`)\"\n            >\n              <div\n                class=\"gatsby-code-button\"\n                data-tooltip=\"\"\n              >\n                <svg class=\"gatsby-code-button-icon\" xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\"><path fill=\"none\" d=\"M0 0h24v24H0V0z\"/><path d=\"M16 1H2v16h2V3h12V1zm-1 4l6 6v12H6V5h9zm-1 7h5.5L14 6.5V12z\"/></svg>\n              </div>\n            </div>\n<div class=\"gatsby-highlight\" data-language=\"tsx\"><pre class=\"language-tsx\"><code class=\"language-tsx\"><span class=\"token comment\">//my-demo-app/src/App.js</span>\n\n<span class=\"token comment\">// imports</span>\n\n<span class=\"token keyword\">import</span> ThirdPartyEmailPassword<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span>\n  ThirdPartyEmailPasswordAuth<span class=\"token punctuation\">,</span>\n  Google<span class=\"token punctuation\">,</span>\n  Github<span class=\"token punctuation\">,</span>\n  Apple<span class=\"token punctuation\">,</span>\n<span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">\"supertokens-auth-react/recipe/thirdpartyemailpassword\"</span><span class=\"token punctuation\">;</span>\n\nSuperTokens<span class=\"token punctuation\">.</span><span class=\"token function\">init</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>\n…\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">App</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>div</span> <span class=\"token attr-name\">className</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>App<span class=\"token punctuation\">\"</span></span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n      </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span><span class=\"token class-name\">Router</span></span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n        </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span><span class=\"token class-name\">Routes</span></span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n          </span><span class=\"token punctuation\">{</span><span class=\"token comment\">/*This renders the login UI on the /auth route*/</span><span class=\"token punctuation\">}</span><span class=\"token plain-text\">\n          </span><span class=\"token punctuation\">{</span><span class=\"token function\">getSuperTokensRoutesForReactRouterDom</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">require</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"react-router-dom\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span><span class=\"token plain-text\">\n          </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span><span class=\"token class-name\">Route</span></span>\n            <span class=\"token attr-name\">path</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>/<span class=\"token punctuation\">\"</span></span>\n            <span class=\"token attr-name\">element</span><span class=\"token script language-javascript\"><span class=\"token script-punctuation punctuation\">=</span><span class=\"token punctuation\">{</span>\n              <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span><span class=\"token class-name\">ThirdPartyEmailPasswordAuth</span></span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n                </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span><span class=\"token class-name\">Home</span></span> <span class=\"token punctuation\">/></span></span><span class=\"token plain-text\">\n              </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span><span class=\"token class-name\">ThirdPartyEmailPasswordAuth</span></span><span class=\"token punctuation\">></span></span>\n            <span class=\"token punctuation\">}</span></span>\n          <span class=\"token punctuation\">/></span></span><span class=\"token plain-text\">\n        </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span><span class=\"token class-name\">Routes</span></span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n      </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span><span class=\"token class-name\">Router</span></span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n    </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>div</span><span class=\"token punctuation\">></span></span>\n  <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">default</span> App<span class=\"token punctuation\">;</span></code></pre></div>\n<p>Now that we have our authentication wrapper, we use the <code class=\"language-text\">sessionContext</code> context, in our Home component, to fetch the <code class=\"language-text\">userId</code> on the frontend. This class can be imported from the supertokens session recipe. Following is how the <code class=\"language-text\">Home</code> component should look like:</p>\n<div\n              class=\"gatsby-code-button-container\"\n              data-toaster-id=\"30981260541268464000\"\n              data-toaster-class=\"gatsby-code-button-toaster\"\n              data-toaster-text-class=\"gatsby-code-button-toaster-text\"\n              data-toaster-text=\"Copied!\"\n              data-toaster-duration=\"3500\"\n              onClick=\"copyToClipboard(`//my-demo-app/src/Home/index.js\n\nimport React from &quot;react&quot;;\nimport Logout from &quot;./Logout&quot;;\nimport { useSessionContext } from &quot;supertokens-auth-react/recipe/session&quot;;\nimport { useNavigate } from &quot;react-router-dom&quot;;\nimport { signOut } from &quot;supertokens-auth-react/recipe/thirdpartyemailpassword&quot;;\n\nexport default function Home() {\n  const { userId } = useSessionContext();\n  const navigate = useNavigate();\n\n  return (\n    <div className=&quot;fill&quot;>\n       {userId}\n    </div>\n  );\n}\n`, `30981260541268464000`)\"\n            >\n              <div\n                class=\"gatsby-code-button\"\n                data-tooltip=\"\"\n              >\n                <svg class=\"gatsby-code-button-icon\" xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\"><path fill=\"none\" d=\"M0 0h24v24H0V0z\"/><path d=\"M16 1H2v16h2V3h12V1zm-1 4l6 6v12H6V5h9zm-1 7h5.5L14 6.5V12z\"/></svg>\n              </div>\n            </div>\n<div class=\"gatsby-highlight\" data-language=\"tsx\"><pre class=\"language-tsx\"><code class=\"language-tsx\"><span class=\"token comment\">//my-demo-app/src/Home/index.js</span>\n\n<span class=\"token keyword\">import</span> React <span class=\"token keyword\">from</span> <span class=\"token string\">\"react\"</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">import</span> Logout <span class=\"token keyword\">from</span> <span class=\"token string\">\"./Logout\"</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">import</span> <span class=\"token punctuation\">{</span> useSessionContext <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">\"supertokens-auth-react/recipe/session\"</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">import</span> <span class=\"token punctuation\">{</span> useNavigate <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">\"react-router-dom\"</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">import</span> <span class=\"token punctuation\">{</span> signOut <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">\"supertokens-auth-react/recipe/thirdpartyemailpassword\"</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">default</span> <span class=\"token keyword\">function</span> <span class=\"token function\">Home</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">const</span> <span class=\"token punctuation\">{</span> userId <span class=\"token punctuation\">}</span> <span class=\"token operator\">=</span> <span class=\"token function\">useSessionContext</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">const</span> navigate <span class=\"token operator\">=</span> <span class=\"token function\">useNavigate</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n  <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>div</span> <span class=\"token attr-name\">className</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>fill<span class=\"token punctuation\">\"</span></span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n       </span><span class=\"token punctuation\">{</span>userId<span class=\"token punctuation\">}</span><span class=\"token plain-text\">\n    </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>div</span><span class=\"token punctuation\">></span></span>\n  <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n</code></pre></div>\n<p>Let’s see how this works, following is the GIF:</p>\n<p><img src=\"/static/blog/c40fcef7ec10b9c98dcf6d07dc744244/gif2forblog.gif\" alt=\"auth flow gif\"></p>\n<p>To implement logout, we call the <code class=\"language-text\">signOut</code> method from the <code class=\"language-text\">ThirPartyEmailPassword</code> recipe. The way it works is, we implement a simple <code class=\"language-text\">logoutClicked</code> function, that awaits for the <code class=\"language-text\">signOut</code> function call and redirects to auth route whenever the logout button is clicked.</p>\n<p>Following is how the <code class=\"language-text\">Home</code> component looks like now:</p>\n<div\n              class=\"gatsby-code-button-container\"\n              data-toaster-id=\"33506676402492030000\"\n              data-toaster-class=\"gatsby-code-button-toaster\"\n              data-toaster-text-class=\"gatsby-code-button-toaster-text\"\n              data-toaster-text=\"Copied!\"\n              data-toaster-duration=\"3500\"\n              onClick=\"copyToClipboard(`import React from &quot;react&quot;;\nimport Logout from &quot;./Logout&quot;;\nimport { useSessionContext } from &quot;supertokens-auth-react/recipe/session&quot;;\nimport { useNavigate } from &quot;react-router-dom&quot;;\nimport { signOut } from &quot;supertokens-auth-react/recipe/thirdpartyemailpassword&quot;;\n\nexport default function Home() {\n  const { userId } = useSessionContext();\n  const navigate = useNavigate();\n\n  async function logoutClicked() {\n    await signOut();\n    navigate(&quot;/auth&quot;);\n  }\n\n  return (\n    <div className=&quot;fill&quot;>\n      <Logout logoutClicked={logoutClicked} />\n      {userId}\n    </div>\n  );\n}`, `33506676402492030000`)\"\n            >\n              <div\n                class=\"gatsby-code-button\"\n                data-tooltip=\"\"\n              >\n                <svg class=\"gatsby-code-button-icon\" xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\"><path fill=\"none\" d=\"M0 0h24v24H0V0z\"/><path d=\"M16 1H2v16h2V3h12V1zm-1 4l6 6v12H6V5h9zm-1 7h5.5L14 6.5V12z\"/></svg>\n              </div>\n            </div>\n<div class=\"gatsby-highlight\" data-language=\"tsx\"><pre class=\"language-tsx\"><code class=\"language-tsx\"><span class=\"token keyword\">import</span> React <span class=\"token keyword\">from</span> <span class=\"token string\">\"react\"</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">import</span> Logout <span class=\"token keyword\">from</span> <span class=\"token string\">\"./Logout\"</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">import</span> <span class=\"token punctuation\">{</span> useSessionContext <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">\"supertokens-auth-react/recipe/session\"</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">import</span> <span class=\"token punctuation\">{</span> useNavigate <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">\"react-router-dom\"</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">import</span> <span class=\"token punctuation\">{</span> signOut <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">\"supertokens-auth-react/recipe/thirdpartyemailpassword\"</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">default</span> <span class=\"token keyword\">function</span> <span class=\"token function\">Home</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">const</span> <span class=\"token punctuation\">{</span> userId <span class=\"token punctuation\">}</span> <span class=\"token operator\">=</span> <span class=\"token function\">useSessionContext</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">const</span> navigate <span class=\"token operator\">=</span> <span class=\"token function\">useNavigate</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n  <span class=\"token keyword\">async</span> <span class=\"token keyword\">function</span> <span class=\"token function\">logoutClicked</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">await</span> <span class=\"token function\">signOut</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token function\">navigate</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"/auth\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n\n  <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>div</span> <span class=\"token attr-name\">className</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>fill<span class=\"token punctuation\">\"</span></span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n      </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span><span class=\"token class-name\">Logout</span></span> <span class=\"token attr-name\">logoutClicked</span><span class=\"token script language-javascript\"><span class=\"token script-punctuation punctuation\">=</span><span class=\"token punctuation\">{</span>logoutClicked<span class=\"token punctuation\">}</span></span> <span class=\"token punctuation\">/></span></span><span class=\"token plain-text\">\n      </span><span class=\"token punctuation\">{</span>userId<span class=\"token punctuation\">}</span><span class=\"token plain-text\">\n    </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>div</span><span class=\"token punctuation\">></span></span>\n  <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>If you notice, there is also a new <code class=\"language-text\">Logout</code> component here, this is basically just a UI component to render the logout button on the home component. We can create this next to the <code class=\"language-text\">Home</code> component:</p>\n<div\n              class=\"gatsby-code-button-container\"\n              data-toaster-id=\"99597810415691070000\"\n              data-toaster-class=\"gatsby-code-button-toaster\"\n              data-toaster-text-class=\"gatsby-code-button-toaster-text\"\n              data-toaster-text=\"Copied!\"\n              data-toaster-duration=\"3500\"\n              onClick=\"copyToClipboard(`//my-demo-app/src/Home/Lougout.js\nexport default function Logout(props) {\n  let logoutClicked = props.logoutClicked;\n\n  return (\n    <div\n      style={{\n        display: &quot;flex&quot;,\n        height: &quot;70px&quot;,\n        alignItems: &quot;center&quot;,\n        justifyContent: &quot;flex-end&quot;,\n        paddingLeft: &quot;75px&quot;,\n        paddingRight: &quot;75px&quot;,\n      }}\n    >\n      <div\n        onClick={logoutClicked}\n        style={{\n          display: &quot;flex&quot;,\n          width: &quot;116px&quot;,\n          height: &quot;42px&quot;,\n          backgroundColor: &quot;#000000&quot;,\n          borderRadius: &quot;10px&quot;,\n          cursor: &quot;pointer&quot;,\n          alignItems: &quot;center&quot;,\n          justifyContent: &quot;center&quot;,\n          color: &quot;#ffffff&quot;,\n          fontWeight: &quot;bold&quot;,\n        }}\n      >\n        {/* SIGN OUT */}\n      </div>\n    </div>\n  );\n}`, `99597810415691070000`)\"\n            >\n              <div\n                class=\"gatsby-code-button\"\n                data-tooltip=\"\"\n              >\n                <svg class=\"gatsby-code-button-icon\" xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\"><path fill=\"none\" d=\"M0 0h24v24H0V0z\"/><path d=\"M16 1H2v16h2V3h12V1zm-1 4l6 6v12H6V5h9zm-1 7h5.5L14 6.5V12z\"/></svg>\n              </div>\n            </div>\n<div class=\"gatsby-highlight\" data-language=\"tsx\"><pre class=\"language-tsx\"><code class=\"language-tsx\"><span class=\"token comment\">//my-demo-app/src/Home/Lougout.js</span>\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">default</span> <span class=\"token keyword\">function</span> <span class=\"token function\">Logout</span><span class=\"token punctuation\">(</span>props<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">let</span> logoutClicked <span class=\"token operator\">=</span> props<span class=\"token punctuation\">.</span>logoutClicked<span class=\"token punctuation\">;</span>\n\n  <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>div</span>\n      <span class=\"token attr-name\">style</span><span class=\"token script language-javascript\"><span class=\"token script-punctuation punctuation\">=</span><span class=\"token punctuation\">{</span><span class=\"token punctuation\">{</span>\n        <span class=\"token literal-property property\">display</span><span class=\"token operator\">:</span> <span class=\"token string\">\"flex\"</span><span class=\"token punctuation\">,</span>\n        <span class=\"token literal-property property\">height</span><span class=\"token operator\">:</span> <span class=\"token string\">\"70px\"</span><span class=\"token punctuation\">,</span>\n        <span class=\"token literal-property property\">alignItems</span><span class=\"token operator\">:</span> <span class=\"token string\">\"center\"</span><span class=\"token punctuation\">,</span>\n        <span class=\"token literal-property property\">justifyContent</span><span class=\"token operator\">:</span> <span class=\"token string\">\"flex-end\"</span><span class=\"token punctuation\">,</span>\n        <span class=\"token literal-property property\">paddingLeft</span><span class=\"token operator\">:</span> <span class=\"token string\">\"75px\"</span><span class=\"token punctuation\">,</span>\n        <span class=\"token literal-property property\">paddingRight</span><span class=\"token operator\">:</span> <span class=\"token string\">\"75px\"</span><span class=\"token punctuation\">,</span>\n      <span class=\"token punctuation\">}</span><span class=\"token punctuation\">}</span></span>\n    <span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n      </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>div</span>\n        <span class=\"token attr-name\">onClick</span><span class=\"token script language-javascript\"><span class=\"token script-punctuation punctuation\">=</span><span class=\"token punctuation\">{</span>logoutClicked<span class=\"token punctuation\">}</span></span>\n        <span class=\"token attr-name\">style</span><span class=\"token script language-javascript\"><span class=\"token script-punctuation punctuation\">=</span><span class=\"token punctuation\">{</span><span class=\"token punctuation\">{</span>\n          <span class=\"token literal-property property\">display</span><span class=\"token operator\">:</span> <span class=\"token string\">\"flex\"</span><span class=\"token punctuation\">,</span>\n          <span class=\"token literal-property property\">width</span><span class=\"token operator\">:</span> <span class=\"token string\">\"116px\"</span><span class=\"token punctuation\">,</span>\n          <span class=\"token literal-property property\">height</span><span class=\"token operator\">:</span> <span class=\"token string\">\"42px\"</span><span class=\"token punctuation\">,</span>\n          <span class=\"token literal-property property\">backgroundColor</span><span class=\"token operator\">:</span> <span class=\"token string\">\"#000000\"</span><span class=\"token punctuation\">,</span>\n          <span class=\"token literal-property property\">borderRadius</span><span class=\"token operator\">:</span> <span class=\"token string\">\"10px\"</span><span class=\"token punctuation\">,</span>\n          <span class=\"token literal-property property\">cursor</span><span class=\"token operator\">:</span> <span class=\"token string\">\"pointer\"</span><span class=\"token punctuation\">,</span>\n          <span class=\"token literal-property property\">alignItems</span><span class=\"token operator\">:</span> <span class=\"token string\">\"center\"</span><span class=\"token punctuation\">,</span>\n          <span class=\"token literal-property property\">justifyContent</span><span class=\"token operator\">:</span> <span class=\"token string\">\"center\"</span><span class=\"token punctuation\">,</span>\n          <span class=\"token literal-property property\">color</span><span class=\"token operator\">:</span> <span class=\"token string\">\"#ffffff\"</span><span class=\"token punctuation\">,</span>\n          <span class=\"token literal-property property\">fontWeight</span><span class=\"token operator\">:</span> <span class=\"token string\">\"bold\"</span><span class=\"token punctuation\">,</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">}</span></span>\n      <span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n        </span><span class=\"token punctuation\">{</span><span class=\"token comment\">/* SIGN OUT */</span><span class=\"token punctuation\">}</span><span class=\"token plain-text\">\n      </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>div</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n    </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>div</span><span class=\"token punctuation\">></span></span>\n  <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>Now whenever you click the Logout button, the session tokens will be deleted on the frontend and backend, and the user will be redirected back to auth page.</p>\n<p>That’s all, we are all set with our authentication!</p>\n<p><img src=\"/static/blog/c40fcef7ec10b9c98dcf6d07dc744244/gif2forblog.gif\" alt=\"auth flow gif\"></p>\n<h2 id=\"setting-up-your-own-core\" style=\"position:relative;\"><a href=\"#setting-up-your-own-core\" aria-label=\"setting up your own core 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 your Own Core</h2>\n<p>In this tutorial we used the example SuperTokens core (<code class=\"language-text\">https://try.supertokens.com</code>), but that’s only meant for getting started. In a development / production env, we must set-up our own core by self-hosting SuperTokens or using the managed service option.</p>\n<p>If we choose the managed service option, SuperTokens cloud will run the Core for us in a region of our choice, note that this also comes with a database to manage all our users. In this mode, we will still need to run a backend API layer which integrates with our backend SDK. The only difference is that instead of pointing to <code class=\"language-text\">https://try.supertokens.com</code>, we must point to the managed service core.</p>\n<p>Following is how we can set-up SuperTokens core on managed service:</p>\n<ul>\n<li>If you’re new user of  SuperTokens, create a new account <a href=\"https://supertokens.com/auth/?redirectToPath=%2Fdashboard-saas\" target=\"_blank\" rel=\"nofollow\">here</a> (it’s free), else you can log in to your existing account.</li>\n<li>Next, under your dashboard, create a new app. After doing so, you’ll land up on your app detail page, where we will find the <code class=\"language-text\">connectionURI</code> and the <code class=\"language-text\">API key</code>. Following is a screenshot of  how it looks (as of 8th Feb, 2022):</li>\n</ul>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 630px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/aff7f727e7b27fdc4db54eb6f66c62f8/29007/imageforblog3.png\"\n    style=\"display: block\"\n    target=\"_blank\"\n    rel=\"noopener\"\n  >\n    <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 62.65822784810127%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAANCAIAAAAmMtkJAAAACXBIWXMAAAsTAAALEwEAmpwYAAABWElEQVQoz42Sy27cMAxF/f//1F13XXXTVRfTaWZs62lZEkVSr8B2JnWCQdCDC4JcXBHS1WCMFlLd7tMk1CzUtEnvVY3zpqOf5rd6n+SLmK7X6XL5O0Q7CyGYudbaWusPWmvMHEJIKSEiJMCdEIEZ2M0FYUBiZkYiANBKjuM47dxvd2ttKbWcoJ3tjL0MiAmPKYGV4yxmo/Xq3RpWQmy1nvXmfDC8dxFwlItUVhsn3eIz1NapND4Jn5oJ0QPr0BJlyp1yB6xAlUo/xkMJ+flmQnSL0VorJY0xKUHO3GrtJ7bXeWpGRO/96pxf19U5iBERmfl/zImYPdaIJSgTZuWkpo/OL8xEKdbbjy5/ZSYmrKV8Sv5LM0T4/T1efy6B1QKU2/FVzpzMhJTPd6bI3WOJEXLe1tZaPumRMyEEDPpfVCHiy2iVtkLZmJhr33L6qESMKSHXZC/w59sr2pPvPE7tPpwAAAAASUVORK5CYII='); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"supertokens dashboard\"\n        title=\"supertokens dashboard\"\n        src=\"/static/aff7f727e7b27fdc4db54eb6f66c62f8/f058b/imageforblog3.png\"\n        srcset=\"/static/aff7f727e7b27fdc4db54eb6f66c62f8/c26ae/imageforblog3.png 158w,\n/static/aff7f727e7b27fdc4db54eb6f66c62f8/6bdcf/imageforblog3.png 315w,\n/static/aff7f727e7b27fdc4db54eb6f66c62f8/f058b/imageforblog3.png 630w,\n/static/aff7f727e7b27fdc4db54eb6f66c62f8/40601/imageforblog3.png 945w,\n/static/aff7f727e7b27fdc4db54eb6f66c62f8/78612/imageforblog3.png 1260w,\n/static/aff7f727e7b27fdc4db54eb6f66c62f8/29007/imageforblog3.png 1600w\"\n        sizes=\"(max-width: 630px) 100vw, 630px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n        decoding=\"async\"\n      />\n  </a>\n    </span></p>\n<p>Copy the <code class=\"language-text\">connectionURI</code> and <code class=\"language-text\">API key</code> and update them on the <code class=\"language-text\">api-server.js</code> file to the <code class=\"language-text\">supertokens</code> object.</p>\n<p>That’s all, with this our core will be pointing out to our newly created Managed Service on SuperTokens :)</p>\n<p>The other alternative is to self-host the SuperTokens core with your own database. You can do this <a href=\"https://supertokens.com/docs/thirdpartyemailpassword/pre-built-ui/setup/core/with-docker\" target=\"_blank\" rel=\"nofollow\">via docker</a> or <a href=\"https://supertokens.com/docs/thirdpartyemailpassword/pre-built-ui/setup/core/without-docker\" target=\"_blank\" rel=\"nofollow\">via manually installing SuperTokens on your system</a>. You will also need to set up your database as shown here for <a href=\"https://supertokens.com/docs/thirdpartyemailpassword/pre-built-ui/setup/database-setup/mysql\" target=\"_blank\" rel=\"nofollow\">mysql</a> or for <a href=\"https://supertokens.com/docs/thirdpartyemailpassword/pre-built-ui/setup/database-setup/postgresql\" target=\"_blank\" rel=\"nofollow\">postgresql</a>.</p>","frontmatter":{"date":"February 09, 2022","title":"How to Set up Social and Email Password Login With ReactJS in 10 Minute","cover":"how-to-set-up-social-and-email-password-login-with-reactjs.png","author":"Rishabh Poddar","description":" In this blog, we'll walk you through setting up an email-password authentication with popular social providers like Google, GitHub, and Apple using SuperTokens on a ReactJS application with ExpressJS as the backend."},"fields":{"slug":"/how-to-set-up-social-and-email-password-login-with-reactjs/"}},"site":{"siteMetadata":{"title":"SuperTokens Blog"}}},"pageContext":{"id":"40b1c27d-7c34-5574-908d-9a5ec9aa7344","fields__slug":"/how-to-set-up-social-and-email-password-login-with-reactjs/","__params":{"fields__slug":"how-to-set-up-social-and-email-password-login-with-reactjs"}}},
    "staticQueryHashes": []}