SolidJSS
SolidJS17mo ago
11 replies
enoro

Cannot call server function outside of a request

Tried to initialize Supertokens backend client in parallel with main router, but got this error: Cannot call server function outside of a request

Supertokens client initializer:
"use server";

import supertokens from "supertokens-node";
import Session from "supertokens-node/recipe/session";
import EmailPassword from "supertokens-node/recipe/emailpassword";

export const initAuthServer = () => {
    supertokens.init({
        framework: "express",
        supertokens: {
            connectionURI:
                "https://st-dev-5b734821-6414-11ef-8c62-03ca6dc7cc97.aws.supertokens.io",
            apiKey: "a9ntJvmIYaQ-iWRUsLnGRDsWV-",
        },
        appInfo: {
            appName: "ficlib",
            apiDomain: "http://localhost:8000",
            websiteDomain: "http://localhost:3000",
            apiBasePath: "/auth",
            websiteBasePath: "/auth",
        },
        recipeList: [EmailPassword.init(), Session.init()],
    });
};


entry-server:
import { createHandler, StartServer } from "@solidjs/start/server";
import { initAuthServer } from "./app/auth/server";

initAuthServer(); // usage

export default createHandler(() => (
    <StartServer
        document={({ assets, children, scripts }) => (
            <html lang="en" class="dark">
                <head>
                    <meta charset="utf-8" />
                    <meta
                        name="viewport"
                        content="width=device-width, initial-scale=1"
                    />
                    {assets}
                </head>
                <body>
                    <div id="app">{children}</div>
                    {scripts}
                </body>
            </html>
        )}
    />
));


I didn't fully understand how to segregate server-side code.
image.png
Was this page helpful?