Skip to content

Error trying to load the supertokensui signup/in component in Vue (using Docs) #1105

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
rezelute opened this issue Feb 6, 2025 · 2 comments
Labels
bug Something isn't working

Comments

@rezelute
Copy link

rezelute commented Feb 6, 2025

🐛 Bug Report

I followed to docs here while setting up a very basic Vue 3 application: https://supertokens.com/docs/quickstart/frontend-setup, but i just get the following console error which is coming from: init genericComponentOverrideContext.js:1339 Uncaught TypeError: n is undefined

<template>
   <div id="supertokensui" />
</template>

<script lang="ts">
import { defineComponent, onMounted, onUnmounted } from "vue";
export default defineComponent({
   setup() {
      const loadScript = (src: string) => {
         const script = document.createElement("script");
         script.type = "text/javascript";
         script.src = src;
         script.id = "supertokens-script";
         script.onload = () => {
            supertokensUIInit({
               appInfo: {
                  appName: "Auth App",
                  apiDomain: "my-api-domain",
                  websiteDomain: "my-app-domain",
                  apiBasePath: "/auth",
                  websiteBasePath: "/auth",
               },
               recipeList: [supertokensUIEmailPassword.init(), supertokensUISession.init()],
            });
         };
         document.body.appendChild(script);
      };

      onMounted(() => {
         loadScript("https://cdn.jsdelivr.net/gh/supertokens/[email protected]/build/static/js/main.81589a39.js");
      });

      onUnmounted(() => {
         const script = document.getElementById("supertokens-script");
         if (script) {
            script.remove();
         }
      });
   },
});
</script>

I then tried to follow the docs for the Custom UI and there is a piece of code missing here:
"After that, call the following function when the user submits the form that you have previously created."

Image

@rezelute rezelute added the bug Something isn't working label Feb 6, 2025
@imxuedi
Copy link

imxuedi commented Apr 14, 2025

I'm having the same issue, the root cause is that the documentation is wrong, the method signature of supertokensUIInit has two arguments, and only one is used here, resulting in the wrong pass of the arguments.

Source Code:

function supertokensUIInit(divId: string, customConfig: any) {
    SuperTokens.init(customConfig);

    let element = document.getElementById(divId);
    if (element !== null) {
        const root = ReactDOM.createRoot(element as HTMLElement);
        root.render(
            <React.StrictMode>
                <App />
            </React.StrictMode>
        );
    }
}

Solving this problem is as simple as updating the mount point parameter of the element (divId)

<template>
    <div id="supertokensui" />
</template>
script.onload = () => {
script.onload = () => {
    (window as any).supertokensUIInit(
        "supertokensui",
        {
            appInfo: {
                appName: "App Name",
                apiDomain: "http://localhost:3000",
                websiteDomain: "http://localhost:5173",
                apiBasePath: "/auth",
                websiteBasePath: "/auth"
            },
            recipeList: [
                (window as any).supertokensUIEmailPassword.init(),
                (window as any).supertokensUISession.init(),
            ],
        });
};

@porcellus
Copy link
Collaborator

@bcbogdan Could you please check on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants