{
    "componentChunkName": "component---src-pages-blog-markdown-remark-fields-slug-js",
    "path": "/blog/how-to-use-supertokens-custom-ui-with-vuejs",
    "result": {"data":{"markdownRemark":{"html":"<p>In this guide, you will learn how to add an Email + Password Authentication to a Vue.js application using SuperTokens. We’ll build a simple web application where users can sign up with their email and password, relying on SuperTokens for authentication.</p>\n<p>Our <a href=\"https://supertokens-vue.vercel.app/\" target=\"_blank\" rel=\"nofollow\">demo app</a> will use the <a href=\"https://supertokens.com/docs/emailpassword/introduction\" target=\"_blank\" rel=\"nofollow\">Email-Password</a> recipe for authentication and a custom authentication user interface (UI) tailored for our users.</p>\n<p><img src=\"/static/blog/daf7a8d92d640c05d9c6b3e087538da3/st-demo-3.gif\" alt=\"Vue Application + Auth Demo\"></p>\n<h2 id=\"prerequisites\" style=\"position:relative;\"><a href=\"#prerequisites\" aria-label=\"prerequisites permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Prerequisites</h2>\n<p>Before you begin, you need:</p>\n<ul>\n<li>A basic knowledge of JavaScript and <a href=\"https://vuejs.org/guide/quick-start.html\" target=\"_blank\" rel=\"nofollow\">Vue.js</a></li>\n<li><a href=\"https://nodejs.org/en/\" target=\"_blank\" rel=\"nofollow\">Node.js</a> installed on your computer</li>\n<li>A <a href=\"https://supertokens.com/\" target=\"_blank\" rel=\"nofollow\">SuperTokens</a> account</li>\n</ul>\n<h2 id=\"what-is-supertokens\" style=\"position:relative;\"><a href=\"#what-is-supertokens\" aria-label=\"what is 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>What is SuperTokens</h2>\n<p>SuperTokens is an open source project that lets you add authentication to your app quickly. It offers various authentication methods (called recipes).</p>\n<p>Alongside a prebuilt UI, it also offers a vanilla JS SDK called <code class=\"language-text\">supertokens-web-js</code> that you can use to build your own UI. In this tutorial we’ll learn how to use the <code class=\"language-text\">supertokens-web-js</code> to add authentication to a VueJS application. We’ll focus on the email password and social login flow, but you can <a href=\"https://supertokens.com/docs/guides\" target=\"_blank\" rel=\"nofollow\">choose another auth method</a> as well.</p>\n<h2 id=\"architecture\" style=\"position:relative;\"><a href=\"#architecture\" aria-label=\"architecture 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>Architecture</h2>\n<p>SuperTokens is built out of three components:</p>\n<ul>\n<li>Frontend SDK</li>\n<li>Backend SDK</li>\n<li>A microservice that talks to a database (called the SuperTokens Core).</li>\n</ul>\n<p>We’ll build our own login, signup forms. Then we’ll use the <code class=\"language-text\">supertokens-web-js</code> SDK in our Vue app to make these forms functional by invoking the relevant functions for each action. These functions will interact with the APIs exposed via the SuperTokens SDK that is integrated into our backend layer.</p>\n<p>For the backend we’ll use the <code class=\"language-text\">supertokens-node</code> SDK. The APIs exposed by this SDK will further talk to the SuperTokens Core to read/write information to the database.</p>\n<p>The SuperTokens core service can be either self hosted (and connected to your own db), or be hosted by the team behind SuperTokens (sign up on <a href=\"https://supertokens.com/\" target=\"_blank\" rel=\"nofollow\">supertokens.com</a>).</p>\n<h2 id=\"project-setup\" style=\"position:relative;\"><a href=\"#project-setup\" aria-label=\"project 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>Project Setup</h2>\n<p>To reduce the scope of this guide, you will be starting with a <a href=\"https://github.com/kohasummons/supertokens-vue\" target=\"_blank\" rel=\"nofollow\">repository</a> that already has a few things set up for you:</p>\n<ul>\n<li>A Simple Vue.js web application</li>\n<li>TailwindCSS for styling and</li>\n<li>Vue Router for in app navigation.</li>\n<li>An express-based backend</li>\n</ul>\n<p>To get started, clone the starter branch from the repository with the following command:</p>\n<div\n              class=\"gatsby-code-button-container\"\n              data-toaster-id=\"77319627848779550000\"\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(`git clone --branch starter https://github.com/kohasummons/supertokens-vue\ncd supertokens-vue`, `77319627848779550000`)\"\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=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">git</span> clone --branch starter https://github.com/kohasummons/supertokens-vue\n<span class=\"token builtin class-name\">cd</span> supertokens-vue</code></pre></div>\n<p>Your project directory structure will look like the tree below with that setup. The <code class=\"language-text\">...</code> indicates omitted files to keep the tree concise.</p>\n<div\n              class=\"gatsby-code-button-container\"\n              data-toaster-id=\"78281159861325840000\"\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(`├── backend\n│   ├── ...\n│   ├── app.js\n└── frontend\n    ├── ...\n    ├── src\n    │   ├── App.vue\n    │   ├── components\n    │   │   ├── HelloWorld.vue\n    │   │   ├── TheButton.vue\n    │   ├── main.ts\n    │   ├── router\n    │   │   └── index.ts\n    │   └── views\n    │       ├── AboutView.vue\n    │       ├── AuthView.vue\n    │       ├── HomeView.vue\n    │       └── UserView.vue`, `78281159861325840000`)\"\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=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">├── backend\n│   ├── <span class=\"token punctuation\">..</span>.\n│   ├── app.js\n└── frontend\n    ├── <span class=\"token punctuation\">..</span>.\n    ├── src\n    │   ├── App.vue\n    │   ├── components\n    │   │   ├── HelloWorld.vue\n    │   │   ├── TheButton.vue\n    │   ├── main.ts\n    │   ├── router\n    │   │   └── index.ts\n    │   └── views\n    │       ├── AboutView.vue\n    │       ├── AuthView.vue\n    │       ├── HomeView.vue\n    │       └── UserView.vue</code></pre></div>\n<ul>\n<li>The backend folder holds the Express.js code for the APIs</li>\n<li>The Frontend folder contains code for the Vue.js application</li>\n</ul>\n<h2 id=\"frontend\" style=\"position:relative;\"><a href=\"#frontend\" aria-label=\"frontend 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>Frontend</h2>\n<p>Change into the <em>Frontend</em> directory and install the <code class=\"language-text\">superTokens-web-js</code> dependency</p>\n<div\n              class=\"gatsby-code-button-container\"\n              data-toaster-id=\"7573844444045696000\"\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 frontend/\nnpm i -s supertokens-web-js`, `7573844444045696000`)\"\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> frontend/\n<span class=\"token function\">npm</span> i -s supertokens-web-js</code></pre></div>\n<h3 id=\"initializing-supertokens\" style=\"position:relative;\"><a href=\"#initializing-supertokens\" aria-label=\"initializing 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>Initializing SuperTokens</h3>\n<p>Open <code class=\"language-text\">main.ts</code> and initialize SuperTokens</p>\n<div\n              class=\"gatsby-code-button-container\"\n              data-toaster-id=\"68034451696198110000\"\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 SuperTokens from 'supertokens-web-js';\nimport Session from 'supertokens-web-js/recipe/session';\nimport EmailPassword from 'supertokens-web-js/recipe/emailpassword'\n\n// Several lines of code are omitted here.\n\nSuperTokens.init({\n    appInfo: {\n        apiDomain: &quot;<YOUR_API_DOMAIN>&quot;, // I use <http://localhost:5175> here\n        apiBasePath: &quot;/auth&quot;,\n        appName: &quot;replace with your app name&quot;,\n    },\n\n    recipeList: [\n        Session.init(),\n        EmailPassword.init(),\n    ],\n});`, `68034451696198110000`)\"\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=\"typescript\"><pre class=\"language-typescript\"><code class=\"language-typescript\"><span class=\"token keyword\">import</span> SuperTokens <span class=\"token keyword\">from</span> <span class=\"token string\">'supertokens-web-js'</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-web-js/recipe/session'</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">import</span> EmailPassword <span class=\"token keyword\">from</span> <span class=\"token string\">'supertokens-web-js/recipe/emailpassword'</span>\n\n<span class=\"token comment\">// Several lines of code are omitted here.</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        apiDomain<span class=\"token operator\">:</span> <span class=\"token string\">\"&lt;YOUR_API_DOMAIN>\"</span><span class=\"token punctuation\">,</span> <span class=\"token comment\">// I use &lt;http://localhost:5175> here</span>\n        apiBasePath<span class=\"token operator\">:</span> <span class=\"token string\">\"/auth\"</span><span class=\"token punctuation\">,</span>\n        appName<span class=\"token operator\">:</span> <span class=\"token string\">\"replace with your app name\"</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n    recipeList<span class=\"token operator\">:</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        EmailPassword<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></code></pre></div>\n<p>In this code snippet, we set up session management network interceptors across the entire application. Our front end will now automatically save and attach session tokens to each request made to our API and auto-refresh sessions.</p>\n<p>This setup also specifies the type of authentication we want to use—in this case, the <code class=\"language-text\">EmailPassword</code> recipe. Additional recipes can be added to the <code class=\"language-text\">recipeList</code> array depending on the project’s needs.</p>\n<p>The <a href=\"https://supertokens.com/docs/thirdpartyemailpassword/appinfo\" target=\"_blank\" rel=\"nofollow\">appInfo object</a> allows us to customize our SuperTokens instance for the application, and it needs to be specified both on the frontend and backend. Some of the options it provides include:</p>\n<ol>\n<li><code class=\"language-text\">appName:</code> The name of your application</li>\n<li><code class=\"language-text\">apiDomain:</code> The API Domain URL of your backend</li>\n<li><code class=\"language-text\">apiBasePath:</code> The base path for the API</li>\n</ol>\n<h3 id=\"add-signin-and-signup-to-your-application\" style=\"position:relative;\"><a href=\"#add-signin-and-signup-to-your-application\" aria-label=\"add signin and signup to your application permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Add SignIn and SignUp to your application</h3>\n<p>Great! Let’s add the ability for our users to sign up via our custom UI. Head to <code class=\"language-text\">AuthView.vue</code> and update with the following code:</p>\n<div\n              class=\"gatsby-code-button-container\"\n              data-toaster-id=\"76087063527781580000\"\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(`<script setup lang=&quot;ts&quot;>\nimport { signIn, signUp } from &quot;supertokens-web-js/recipe/emailpassword&quot;;\n// Several lines of code are omitted here.\n\nconst onSignUp = async () => {\n    try {\n        let response = await signUp({\n            formFields: [{\n                id: &quot;email&quot;,\n                value: email.value\n            }, {\n                id: &quot;password&quot;,\n                value: password.value\n            }]\n        })\n\n       // handle potential errors\n        if (response.status === &quot;FIELD_ERROR&quot;) {\n            // one of the input formFields failed validaiton\n            response.formFields.forEach(formField => {\n                if (formField.id === &quot;email&quot;) {\n                    // Email validation failed\n                    window.alert(formField.error)\n                } else if (formField.id === &quot;password&quot;) {\n                    // Password validation failed.\n                    // Maybe it didn't match the password strength\n                    window.alert(formField.error)\n                }\n            })\n        } else if (response.status === &quot;SIGN_UP_NOT_ALLOWED&quot;) {\n            // the reason string is a user friendly message\n            // about what went wrong.\n            window.alert(response.reason)\n        } else {\n            // sign up successful.\n            // navigate to the '/user' page\n            router.push({ name: 'user' })\n        }\n    } catch (err: any) {\n        if (err.isSuperTokensGeneralError === true) {\n            // this may be a custom error message sent from the API by you.\n            window.alert(err.message);\n        } else {\n            window.alert(&quot;Oops! Something went wrong.&quot;);\n        }\n    }\n}\n</script>`, `76087063527781580000`)\"\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=\"typescript\"><pre class=\"language-typescript\"><code class=\"language-typescript\"><span class=\"token operator\">&lt;</span>script setup lang<span class=\"token operator\">=</span><span class=\"token string\">\"ts\"</span><span class=\"token operator\">></span>\n<span class=\"token keyword\">import</span> <span class=\"token punctuation\">{</span> signIn<span class=\"token punctuation\">,</span> signUp <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">\"supertokens-web-js/recipe/emailpassword\"</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">// Several lines of code are omitted here.</span>\n\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">onSignUp</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">async</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 keyword\">try</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">let</span> response <span class=\"token operator\">=</span> <span class=\"token keyword\">await</span> <span class=\"token function\">signUp</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>\n            formFields<span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">{</span>\n                id<span class=\"token operator\">:</span> <span class=\"token string\">\"email\"</span><span class=\"token punctuation\">,</span>\n                value<span class=\"token operator\">:</span> email<span class=\"token punctuation\">.</span>value\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span>\n                id<span class=\"token operator\">:</span> <span class=\"token string\">\"password\"</span><span class=\"token punctuation\">,</span>\n                value<span class=\"token operator\">:</span> password<span class=\"token punctuation\">.</span>value\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">]</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n\n       <span class=\"token comment\">// handle potential errors</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>response<span class=\"token punctuation\">.</span>status <span class=\"token operator\">===</span> <span class=\"token string\">\"FIELD_ERROR\"</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token comment\">// one of the input formFields failed validaiton</span>\n            response<span class=\"token punctuation\">.</span>formFields<span class=\"token punctuation\">.</span><span class=\"token function\">forEach</span><span class=\"token punctuation\">(</span>formField <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>formField<span class=\"token punctuation\">.</span>id <span class=\"token operator\">===</span> <span class=\"token string\">\"email\"</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token comment\">// Email validation failed</span>\n                    window<span class=\"token punctuation\">.</span><span class=\"token function\">alert</span><span class=\"token punctuation\">(</span>formField<span class=\"token punctuation\">.</span>error<span class=\"token punctuation\">)</span>\n                <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>formField<span class=\"token punctuation\">.</span>id <span class=\"token operator\">===</span> <span class=\"token string\">\"password\"</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token comment\">// Password validation failed.</span>\n                    <span class=\"token comment\">// Maybe it didn't match the password strength</span>\n                    window<span class=\"token punctuation\">.</span><span class=\"token function\">alert</span><span class=\"token punctuation\">(</span>formField<span class=\"token punctuation\">.</span>error<span class=\"token punctuation\">)</span>\n                <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 keyword\">else</span> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>response<span class=\"token punctuation\">.</span>status <span class=\"token operator\">===</span> <span class=\"token string\">\"SIGN_UP_NOT_ALLOWED\"</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token comment\">// the reason string is a user friendly message</span>\n            <span class=\"token comment\">// about what went wrong.</span>\n            window<span class=\"token punctuation\">.</span><span class=\"token function\">alert</span><span class=\"token punctuation\">(</span>response<span class=\"token punctuation\">.</span>reason<span class=\"token punctuation\">)</span>\n        <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token comment\">// sign up successful.</span>\n            <span class=\"token comment\">// navigate to the '/user' page</span>\n            router<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> name<span class=\"token operator\">:</span> <span class=\"token string\">'user'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span> <span class=\"token keyword\">catch</span> <span class=\"token punctuation\">(</span>err<span class=\"token operator\">:</span> <span class=\"token builtin\">any</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>err<span class=\"token punctuation\">.</span>isSuperTokensGeneralError <span class=\"token operator\">===</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token comment\">// this may be a custom error message sent from the API by you.</span>\n            window<span class=\"token punctuation\">.</span><span class=\"token function\">alert</span><span class=\"token punctuation\">(</span>err<span class=\"token punctuation\">.</span>message<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n            window<span class=\"token punctuation\">.</span><span class=\"token function\">alert</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Oops! Something went wrong.\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>script<span class=\"token operator\">></span></code></pre></div>\n<p>The <code class=\"language-text\">onSignUp</code> function calls the <code class=\"language-text\">signIn</code> method from <code class=\"language-text\">supertokens-web-js</code> SDK which receives the email and password. If authentication is successful, we redirect the user to the <code class=\"language-text\">\"/user\"</code> route.</p>\n<p>Next, let’s handle the <code class=\"language-text\">SignIn</code> action. Update the <code class=\"language-text\">AuthView.vue</code> with the following code:</p>\n<div\n              class=\"gatsby-code-button-container\"\n              data-toaster-id=\"22599438821196550000\"\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(`<script setup lang=&quot;ts&quot;>\n// Several lines of code are omitted here.\n\nconst onSignIn = async () => {\n    if (!email.value || !password.value) return\n\n    try {\n        let response = await signIn({\n            formFields: [{\n                id: &quot;email&quot;,\n                value: email.value\n            }, {\n                id: &quot;password&quot;,\n                value: password.value\n            }]\n        })\n\n        if (response.status === &quot;FIELD_ERROR&quot;) {\n            response.formFields.forEach(formField => {\n                if (formField.id === &quot;email&quot;) {\n                    // Email validation failed\n                    // (for example, incorrect email syntax).\n                    window.alert(formField.error)\n                }\n            })\n        } else if (response.status === &quot;WRONG_CREDENTIALS_ERROR&quot;) {\n            window.alert(&quot;Email password combination is incorrect.&quot;)\n        } else if (response.status === &quot;SIGN_IN_NOT_ALLOWED&quot;) {\n            //The reason string is a user-friendly message\n            // about what went wrong.\n            window.alert(response.reason)\n        } else {\n            //sign-in successful.\n            // navigate to the &quot;/user&quot; page\n            router.push({ name: 'user' })\n        }\n    } catch (err: any) {\n        if (err.isSuperTokensGeneralError === true) {\n            // this may be a custom error message\n            // sent from your API.\n            window.alert(err.message);\n        } else {\n            window.alert(&quot;Oops! Something went wrong.&quot;);\n        }\n    }\n}\n</script>`, `22599438821196550000`)\"\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=\"typescript\"><pre class=\"language-typescript\"><code class=\"language-typescript\"><span class=\"token operator\">&lt;</span>script setup lang<span class=\"token operator\">=</span><span class=\"token string\">\"ts\"</span><span class=\"token operator\">></span>\n<span class=\"token comment\">// Several lines of code are omitted here.</span>\n\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">onSignIn</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">async</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 keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>email<span class=\"token punctuation\">.</span>value <span class=\"token operator\">||</span> <span class=\"token operator\">!</span>password<span class=\"token punctuation\">.</span>value<span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span>\n\n    <span class=\"token keyword\">try</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">let</span> response <span class=\"token operator\">=</span> <span class=\"token keyword\">await</span> <span class=\"token function\">signIn</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>\n            formFields<span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">{</span>\n                id<span class=\"token operator\">:</span> <span class=\"token string\">\"email\"</span><span class=\"token punctuation\">,</span>\n                value<span class=\"token operator\">:</span> email<span class=\"token punctuation\">.</span>value\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span>\n                id<span class=\"token operator\">:</span> <span class=\"token string\">\"password\"</span><span class=\"token punctuation\">,</span>\n                value<span class=\"token operator\">:</span> password<span class=\"token punctuation\">.</span>value\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">]</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>response<span class=\"token punctuation\">.</span>status <span class=\"token operator\">===</span> <span class=\"token string\">\"FIELD_ERROR\"</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            response<span class=\"token punctuation\">.</span>formFields<span class=\"token punctuation\">.</span><span class=\"token function\">forEach</span><span class=\"token punctuation\">(</span>formField <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>formField<span class=\"token punctuation\">.</span>id <span class=\"token operator\">===</span> <span class=\"token string\">\"email\"</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token comment\">// Email validation failed</span>\n                    <span class=\"token comment\">// (for example, incorrect email syntax).</span>\n                    window<span class=\"token punctuation\">.</span><span class=\"token function\">alert</span><span class=\"token punctuation\">(</span>formField<span class=\"token punctuation\">.</span>error<span class=\"token punctuation\">)</span>\n                <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 keyword\">else</span> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>response<span class=\"token punctuation\">.</span>status <span class=\"token operator\">===</span> <span class=\"token string\">\"WRONG_CREDENTIALS_ERROR\"</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            window<span class=\"token punctuation\">.</span><span class=\"token function\">alert</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Email password combination is incorrect.\"</span><span class=\"token punctuation\">)</span>\n        <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>response<span class=\"token punctuation\">.</span>status <span class=\"token operator\">===</span> <span class=\"token string\">\"SIGN_IN_NOT_ALLOWED\"</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token comment\">//The reason string is a user-friendly message</span>\n            <span class=\"token comment\">// about what went wrong.</span>\n            window<span class=\"token punctuation\">.</span><span class=\"token function\">alert</span><span class=\"token punctuation\">(</span>response<span class=\"token punctuation\">.</span>reason<span class=\"token punctuation\">)</span>\n        <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token comment\">//sign-in successful.</span>\n            <span class=\"token comment\">// navigate to the \"/user\" page</span>\n            router<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> name<span class=\"token operator\">:</span> <span class=\"token string\">'user'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span> <span class=\"token keyword\">catch</span> <span class=\"token punctuation\">(</span>err<span class=\"token operator\">:</span> <span class=\"token builtin\">any</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>err<span class=\"token punctuation\">.</span>isSuperTokensGeneralError <span class=\"token operator\">===</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token comment\">// this may be a custom error message</span>\n            <span class=\"token comment\">// sent from your API.</span>\n            window<span class=\"token punctuation\">.</span><span class=\"token function\">alert</span><span class=\"token punctuation\">(</span>err<span class=\"token punctuation\">.</span>message<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n            window<span class=\"token punctuation\">.</span><span class=\"token function\">alert</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Oops! Something went wrong.\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>script<span class=\"token operator\">></span></code></pre></div>\n<p>The <code class=\"language-text\">SignIn</code> function works similarly to the <code class=\"language-text\">SignUp</code> function we implemented earlier. We pass the email and password to the <code class=\"language-text\">SignIn</code> function, check for and handle any errors, and then automatically navigate the user if the action is successful.</p>\n<h2 id=\"add-signout-to-your-application\" style=\"position:relative;\"><a href=\"#add-signout-to-your-application\" aria-label=\"add signout to your application permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Add SignOut to your application</h2>\n<p>Users who sign in to your application will also need a way to sign out. Let’s add a SignOut functionality to the <code class=\"language-text\">user</code> page.</p>\n<p>Open <code class=\"language-text\">Userview.vue</code> and update with the following code:</p>\n<div\n              class=\"gatsby-code-button-container\"\n              data-toaster-id=\"22491142270354424000\"\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(`//Several lines of code are omitted here\nimport Session from &quot;supertokens-web-js/recipe/session&quot;;\n\nasync function onSignOut() {\n    await Session.signOut();\n    router.push({ name: 'auth' });\n}`, `22491142270354424000`)\"\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=\"typescript\"><pre class=\"language-typescript\"><code class=\"language-typescript\"><span class=\"token comment\">//Several lines of code are omitted here</span>\n<span class=\"token keyword\">import</span> Session <span class=\"token keyword\">from</span> <span class=\"token string\">\"supertokens-web-js/recipe/session\"</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">async</span> <span class=\"token keyword\">function</span> <span class=\"token function\">onSignOut</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">await</span> Session<span class=\"token punctuation\">.</span><span class=\"token function\">signOut</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    router<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> name<span class=\"token operator\">:</span> <span class=\"token string\">'auth'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h2 id=\"backend\" style=\"position:relative;\"><a href=\"#backend\" aria-label=\"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>Backend</h2>\n<p>While your front end is fully integrated with SuperTokens, it isn’t doing anything yet. That’s because the front end will never directly talk to the SuperTokens core. Any request from the front end will be sent to the APIs exposed on your backend via the <code class=\"language-text\">supertokens-node</code> SDK, which will then talk to the SuperTokens core. Let’s get our backend up and running.</p>\n<p>For a quick backend setup, check out the <a href=\"https://supertokens.com/docs/thirdpartyemailpassword/quick-setup/backend\" target=\"_blank\" rel=\"nofollow\">backend quick setup section in SuperTokens docs</a>.</p>\n<p>Change into the <em>Backend</em> directory and install <code class=\"language-text\">supertokens-node</code> dependency</p>\n<div\n              class=\"gatsby-code-button-container\"\n              data-toaster-id=\"86011086240107710000\"\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 backend\nnpm i -s supertokens-node`, `86011086240107710000`)\"\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> backend\n<span class=\"token function\">npm</span> i -s supertokens-node</code></pre></div>\n<p>Open app.js and update with the following code</p>\n<div\n              class=\"gatsby-code-button-container\"\n              data-toaster-id=\"468252811946756600\"\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 supertokens from &quot;supertokens-node&quot;;\nimport Session from &quot;supertokens-node/recipe/session/index.js&quot;;\nimport EmailPassword from &quot;supertokens-node/recipe/emailpassword/index.js&quot;;\nimport { verifySession } from &quot;supertokens-node/recipe/session/framework/express/index.js&quot;;\nimport { middleware, errorHandler } from 'supertokens-node/framework/express/index.js';\n\nsupertokens.init({\n    framework: &quot;express&quot;,\n    supertokens: {\n        // These are the connection details of\n        // the app you created on supertokens.com\n        connectionURI: \\`<replace with your URI>\\`,\n        apiKey: \\`<replace with your apiKey>\\`,\n    },\n\n    appInfo: {\n        // learn more: <https://supertokens.com/docs/session/appinfo>\n        appName: &quot;replace with your app name&quot;,\n        apiDomain: &quot;<YOUR_API_DOMAIN>&quot;, // I use <http://localhost:5175> here\n        websiteDomain: &quot;<YOUR_WEBSITE_DOMAIN>&quot;,// I use <http://localhost:5173> here\n        apiBasePath: &quot;/auth&quot;,\n        websiteBasePath: &quot;/auth&quot;,\n    },\n\n    recipeList: [\n        EmailPassword.init(), // initializes signin / sign up features\n        Session.init(), // initializes session features\n    ]\n});`, `468252811946756600`)\"\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=\"typescript\"><pre class=\"language-typescript\"><code class=\"language-typescript\"><span class=\"token keyword\">import</span> supertokens <span class=\"token keyword\">from</span> <span class=\"token string\">\"supertokens-node\"</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-node/recipe/session/index.js\"</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">import</span> EmailPassword <span class=\"token keyword\">from</span> <span class=\"token string\">\"supertokens-node/recipe/emailpassword/index.js\"</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">import</span> <span class=\"token punctuation\">{</span> verifySession <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">\"supertokens-node/recipe/session/framework/express/index.js\"</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">import</span> <span class=\"token punctuation\">{</span> middleware<span class=\"token punctuation\">,</span> errorHandler <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">'supertokens-node/framework/express/index.js'</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        <span class=\"token comment\">// These are the connection details of</span>\n        <span class=\"token comment\">// the app you created on supertokens.com</span>\n        connectionURI<span class=\"token operator\">:</span> <span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">&lt;replace with your URI></span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">,</span>\n        apiKey<span class=\"token operator\">:</span> <span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">&lt;replace with your apiKey></span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n    appInfo<span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">// learn more: &lt;https://supertokens.com/docs/session/appinfo></span>\n        appName<span class=\"token operator\">:</span> <span class=\"token string\">\"replace with your app name\"</span><span class=\"token punctuation\">,</span>\n        apiDomain<span class=\"token operator\">:</span> <span class=\"token string\">\"&lt;YOUR_API_DOMAIN>\"</span><span class=\"token punctuation\">,</span> <span class=\"token comment\">// I use &lt;http://localhost:5175> here</span>\n        websiteDomain<span class=\"token operator\">:</span> <span class=\"token string\">\"&lt;YOUR_WEBSITE_DOMAIN>\"</span><span class=\"token punctuation\">,</span><span class=\"token comment\">// I use &lt;http://localhost:5173> here</span>\n        apiBasePath<span class=\"token operator\">:</span> <span class=\"token string\">\"/auth\"</span><span class=\"token punctuation\">,</span>\n        websiteBasePath<span class=\"token operator\">:</span> <span class=\"token string\">\"/auth\"</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n    recipeList<span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span>\n        EmailPassword<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 signin / sign up features</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>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>This will initialize the <code class=\"language-text\">supertokens-node</code> SDK and allow us to customize our authentication flow.\nOnce again, the <code class=\"language-text\">recipeList</code> array configures the type of authentication we prefer, similar to how you did on the front end. The <code class=\"language-text\">appInfo</code> object also behaves like it was on the front end.</p>\n<p>Next, let’s setup <code class=\"language-text\">CORS</code> and the  SuperTokens <code class=\"language-text\">middleware</code> and <code class=\"language-text\">errorHandler</code>:</p>\n<div\n              class=\"gatsby-code-button-container\"\n              data-toaster-id=\"58301201847426660000\"\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(`// several lines have been omitted\n\n// Add \\`cors\\` middleware BEFORE the SuperTokens middleware\napp.use(cors({\n    origin: &quot;<YOUR_WEBSITE_DOMAIN>&quot;,\n    allowedHeaders: [&quot;content-type&quot;, ...supertokens.getAllCORSHeaders()],\n    credentials: true\n}))\n\n// Add the middleware BEFORE all your routes.\napp.use(middleware());\n\n// you can add any other route here.\n\n\napp.use(errorHandler());`, `58301201847426660000`)\"\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=\"typescript\"><pre class=\"language-typescript\"><code class=\"language-typescript\"><span class=\"token comment\">// several lines have been omitted</span>\n\n<span class=\"token comment\">// Add `cors` middleware BEFORE the SuperTokens middleware</span>\napp<span class=\"token punctuation\">.</span><span class=\"token function\">use</span><span class=\"token punctuation\">(</span><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\">\"&lt;YOUR_WEBSITE_DOMAIN>\"</span><span class=\"token punctuation\">,</span>\n    allowedHeaders<span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span><span class=\"token string\">\"content-type\"</span><span class=\"token punctuation\">,</span> <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>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token comment\">// Add the middleware BEFORE 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\">middleware</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">// you can add any other route here.</span>\n\n\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><span class=\"token punctuation\">;</span></code></pre></div>\n<p>This <code class=\"language-text\">middleware</code> exposes all the auth-related API routes (like sign-in and sign-up) to the front end…</p>\n<ul>\n<li><code class=\"language-text\">POST /auth/signup</code>: For signing up a user with email &#x26; password</li>\n<li><code class=\"language-text\">POST /auth/signin</code>: For signing in a user with email &#x26; password</li>\n</ul>\n<h3 id=\"set-up-your-supertokens-core-instance\" style=\"position:relative;\"><a href=\"#set-up-your-supertokens-core-instance\" aria-label=\"set up your supertokens core instance permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a><strong>Set up your SuperTokens Core Instance</strong></h3>\n<p>There are two ways to set up your core instance:</p>\n<ol>\n<li>\n<p><strong>Self-Hosting the Core Instance</strong>:\nSelf-hosting allows you to use all the open-source features of SuperTokens for free, regardless of “scale”. Everything is managed within your infrastructure, giving you full control over the deployment.</p>\n</li>\n<li>\n<p><strong>Using the SuperTokens Managed Service</strong>:\nWith this option, SuperTokens takes care of scalability, reliability, and updates on your behalf, significantly reducing your DevOps workload. It offers the same features as the self-hosted version but with the added convenience of on-demand management and infrastructure support.</p>\n</li>\n</ol>\n<p>For the scope of this tutorial, we’ll spin a SuperTokens managed service instance.</p>\n<p>Create a user account on Supertokens\n<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/61955f2dc2254e066e20b45c04900747/e8950/st-auth-config.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: 57.59493670886076%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAMCAIAAADtbgqsAAAACXBIWXMAAAsTAAALEwEAmpwYAAAA40lEQVQoz5WR3WrEIBBG9/0fsjelYDZm1XF+HGdMSjYtFEo36UH06nDg86ZcrUydwdx77+0/3LA84sfbMr3P8wwA6zVUdZdZJOVSAFJKhzzGWNd1e8mXbGaIFUohIiaqFQiRCN39XO6955RCCESo2phZhLW1S2V3R8ScHgRpmu5NRLWZ2SWZmWOMUwhY4ZmV3ruqikj7u/9jsPRYloiI/RcnchuSEOKS5vmecx7u+xl+aTBzo2a5tgqA+84kB8wvPuy77BIhhXAPIZRcxjP6vGxbz8rDvdlW2Y8aIu4PkzBvZ+VPRSa+2+nLMwcAAAAASUVORK5CYII='); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"Configure Auth Method\"\n        title=\"Configure Auth Method\"\n        src=\"/static/61955f2dc2254e066e20b45c04900747/f058b/st-auth-config.png\"\n        srcset=\"/static/61955f2dc2254e066e20b45c04900747/c26ae/st-auth-config.png 158w,\n/static/61955f2dc2254e066e20b45c04900747/6bdcf/st-auth-config.png 315w,\n/static/61955f2dc2254e066e20b45c04900747/f058b/st-auth-config.png 630w,\n/static/61955f2dc2254e066e20b45c04900747/40601/st-auth-config.png 945w,\n/static/61955f2dc2254e066e20b45c04900747/78612/st-auth-config.png 1260w,\n/static/61955f2dc2254e066e20b45c04900747/e8950/st-auth-config.png 2000w\"\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>Select a region and click the deploy button:\n<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/cf2bc849a9dca05b6ab831d50103cd44/e8950/st-region-config.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: 34.177215189873415%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAHCAIAAACHqfpvAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAzUlEQVQY04WPMU4DQQxFc/8DINHmBNwCCjpQJApAKTbJeofZZNcejzO2B2WUZkWAJ8vVf9L/q1x4xBFgAIAQQoxRVd3dGu5ef+DuIpJzXhUtzDRAH0IAgGGAlCjRFTP7S1YzYdx+vu93+67rQg8049wgInfPzIgzIiZCYVrIZkqch3Gak0zIiHw6HqfpFGMkukRVVUsply925mVtc6Mv2b0UeCuHzTl8eJv62+ClXKv1m/x4J8/r/HRfXh9qve3ckEVEzbTW63nr+R+58Q3hDpYDKsrmXgAAAABJRU5ErkJggg=='); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"Configure Region\"\n        title=\"Configure Region\"\n        src=\"/static/cf2bc849a9dca05b6ab831d50103cd44/f058b/st-region-config.png\"\n        srcset=\"/static/cf2bc849a9dca05b6ab831d50103cd44/c26ae/st-region-config.png 158w,\n/static/cf2bc849a9dca05b6ab831d50103cd44/6bdcf/st-region-config.png 315w,\n/static/cf2bc849a9dca05b6ab831d50103cd44/f058b/st-region-config.png 630w,\n/static/cf2bc849a9dca05b6ab831d50103cd44/40601/st-region-config.png 945w,\n/static/cf2bc849a9dca05b6ab831d50103cd44/78612/st-region-config.png 1260w,\n/static/cf2bc849a9dca05b6ab831d50103cd44/e8950/st-region-config.png 2000w\"\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>After the deployment is complete, the dashboard will look similar to this\n<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/a9c762514feec71eea3a76325d9b17f1/e8950/st-dev-environ.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: 74.68354430379746%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAPCAIAAABr+ngCAAAACXBIWXMAAAsTAAALEwEAmpwYAAABoklEQVQoz3WRi46jMAxF+/8/uNqRpi0IqhICIQ8/YgcYAZ3Zdrd7dKVEUY7sxCdmJsTq8jkMQ9M0dV3fmqZtHrRta62d/0FViei0y9Cefxljfn98nC/Xe2eG0d1uN2OMtdY5t67r8sqTTASIiKSZBaNSVE7zXA6Oe39gpl1h5tOxeO+ZSKMV1+rU6nTLCKIqqlm4PKEiqppzflRGxLq6ns/nqqqapq3quqqqy/Uymh7AX8JnWcr6TfG+WKt7/RMzJZQ+zCGJC4R5AZ6BZ+RlS95Csv4EeUYqSGWrnJnGKJVdfNIQmWV5yvomuoXyLhNRUZVMANuvAUA6iDF4H4JnpnVdftpel21fyrecc/beO+dijM5NfgcAluXJeeUh844xpuu6vu+7+73runvXDcNwDEJEEFFE3shEJDvHwHPOmRkBCRH25lNKAKCq72VVBYBpmsZxRERGinaMg4t2hGGK3jPz+7YP+Ri6qpZSttqIGYkBGfBo/q/3v8gpJefco4sIUz/6fvRmiHb00xRTnOf5v2/WnW0jklD7IH2QgLIfbudv5S/2DGLGHOoyAgAAAABJRU5ErkJggg=='); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"Dashbord\"\n        title=\"Dashbord\"\n        src=\"/static/a9c762514feec71eea3a76325d9b17f1/f058b/st-dev-environ.png\"\n        srcset=\"/static/a9c762514feec71eea3a76325d9b17f1/c26ae/st-dev-environ.png 158w,\n/static/a9c762514feec71eea3a76325d9b17f1/6bdcf/st-dev-environ.png 315w,\n/static/a9c762514feec71eea3a76325d9b17f1/f058b/st-dev-environ.png 630w,\n/static/a9c762514feec71eea3a76325d9b17f1/40601/st-dev-environ.png 945w,\n/static/a9c762514feec71eea3a76325d9b17f1/78612/st-dev-environ.png 1260w,\n/static/a9c762514feec71eea3a76325d9b17f1/e8950/st-dev-environ.png 2000w\"\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<h2 id=\"testing-it-out\" style=\"position:relative;\"><a href=\"#testing-it-out\" aria-label=\"testing it out permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Testing it out</h2>\n<p>Now, we can test everything out.</p>\n<p>With both the frontend and backend servers running, open your application URL in the browser. Navigate to the Auth page and sign up or sign in.</p>\n<p>You’ll be redirected to the User page if the sign-in or sign-up is successful.</p>\n<p><img src=\"/static/blog/daf7a8d92d640c05d9c6b3e087538da3/st-demo-3.gif\" alt=\"Testing\"></p>\n<p>The User page in our demo displays some metadata about the user. That is a little task for you to implement. Look through the <a href=\"https://supertokens.com/docs/emailpassword/common-customizations/get-user-info#fetching-information-using-the-users-id\" target=\"_blank\" rel=\"nofollow\">docs</a> and give it a shot. Useful Resource: <a href=\"https://supertokens.com/docs/emailpassword/common-customizations/get-user-info#fetching-information-using-the-users-id\" target=\"_blank\" rel=\"nofollow\">Getting User Info</a></p>\n<h3 id=\"protecting-your-frontend-routes\" style=\"position:relative;\"><a href=\"#protecting-your-frontend-routes\" aria-label=\"protecting your frontend routes permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Protecting your Frontend Routes</h3>\n<p>You can keep unauthenticated users away from certain page routes using navigation guards.</p>\n<p>To protect the User Page route, navigate to the <code class=\"language-text\">router</code> directory and update <code class=\"language-text\">index.ts</code> with the following code:</p>\n<div\n              class=\"gatsby-code-button-container\"\n              data-toaster-id=\"70322030232477270000\"\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 Session from 'supertokens-web-js/recipe/session';\n\n// several omitted lines of code\n\nrouter.beforeEach(async (to, from, next) => {\n  if (to.name === 'user' && !(await Session.doesSessionExist())) {\n\t  next({ name: 'auth' })\n  }\n    else {\n\t    next();\n    }\n})`, `70322030232477270000`)\"\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=\"typescript\"><pre class=\"language-typescript\"><code class=\"language-typescript\"><span class=\"token keyword\">import</span> Session <span class=\"token keyword\">from</span> <span class=\"token string\">'supertokens-web-js/recipe/session'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">// several omitted lines of code</span>\n\nrouter<span class=\"token punctuation\">.</span><span class=\"token function\">beforeEach</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">async</span> <span class=\"token punctuation\">(</span>to<span class=\"token punctuation\">,</span> from<span class=\"token punctuation\">,</span> next<span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>to<span class=\"token punctuation\">.</span>name <span class=\"token operator\">===</span> <span class=\"token string\">'user'</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token operator\">!</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">await</span> Session<span class=\"token punctuation\">.</span><span class=\"token function\">doesSessionExist</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\t  <span class=\"token function\">next</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> name<span class=\"token operator\">:</span> <span class=\"token string\">'auth'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n  <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n\t    <span class=\"token function\">next</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>The <code class=\"language-text\">router.beforeEach</code> function runs before every route is resolved. We’ve added logic to check if a user session exists. If it does, it navigates to the user page; otherwise, it redirects to the auth page, prompting users to sign in.</p>\n<h2 id=\"conclusion\" style=\"position:relative;\"><a href=\"#conclusion\" aria-label=\"conclusion permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Conclusion</h2>\n<p>With this tutorial, you’ve successfully implemented Email + Password authentication using <code class=\"language-text\">supertokens-web-js</code> SDK in a Vue.js application and a Custom UI.</p>\n<p>You’ve learned how to set up SuperTokens on both the frontend and backend, create a SuperTokens managed service, and protect your frontend routes using navigation guards in combination with SuperTokens.</p>\n<p>Useful links:</p>\n<ul>\n<li><a href=\"https://github.com/kohasummons/supertokens-vue\" target=\"_blank\" rel=\"nofollow\">Vue app</a></li>\n<li><a href=\"https://supertokens.com/discord\" target=\"_blank\" rel=\"nofollow\">Discord community (to ask questions)</a></li>\n<li><a href=\"https://supertokens.com/docs/guides\" target=\"_blank\" rel=\"nofollow\">List of recipes / auth methods</a></li>\n</ul>","frontmatter":{"date":"October 07, 2024","title":"How to use SuperTokens in a VueJS app with your own UI","cover":"vue-custom-ui.png","author":"Joshua Omobola","description":"Learn how to integrate supertokens-web-js SDK into your VueJS application."},"fields":{"slug":"/how-to-use-supertokens-custom-ui-with-vuejs/"}},"site":{"siteMetadata":{"title":"SuperTokens Blog"}}},"pageContext":{"id":"16a9de13-d379-5466-ba96-da941fe25048","fields__slug":"/how-to-use-supertokens-custom-ui-with-vuejs/","__params":{"fields__slug":"how-to-use-supertokens-custom-ui-with-vuejs"}}},
    "staticQueryHashes": []}