drifter2412
11/19/2023, 7:54 PMsupertokens-auth-react
and react-router-dom
) but I'm hitting an issue when the app loads:
Uncaught Error: No instance of Passwordless found. Make sure to call the Passwordless.init method
I'm initialising SuperTokens and Passwordless at the root of my application (see thread for code snippets) and I've checked and all the imports resolve to the same module in case they were pointing at different ones and using different contexts so I'm a little confused 😆 . Can anyone point me in the direction of where I might be going wrong please?drifter2412
11/19/2023, 7:54 PMimport SuperTokens from "supertokens-auth-react";
import Passwordless from "supertokens-auth-react/recipe/passwordless";
import Session from "supertokens-auth-react/recipe/session";
SuperTokens.init({
appInfo: {
appName: "local",
apiDomain: "http://localhost:4000",
websiteDomain: "http://localhost:3000",
apiBasePath: "/auth",
websiteBasePath: "/auth",
},
recipeList: [
Passwordless.init({
contactMethod: "EMAIL",
}),
Session.init(),
],
});
And have the following in my router:
import * as reactRouterDom from "react-router-dom";
import { createBrowserRouter } from "react-router-dom";
import { PasswordlessPreBuiltUI } from "supertokens-auth-react/recipe/passwordless/prebuiltui";
import { getSuperTokensRoutesForReactRouterDom } from "supertokens-auth-react/ui";
export const App: React.FC = () => {
return (
<SuperTokensWrapper>
<RouterProvider router={AppRouter} />
</SuperTokensWrapper>
);
};
export const AppRouter: ReturnType<typeof createBrowserRouter> =
createBrowserRouter([
...getSuperTokensRoutesForReactRouterDom(reactRouterDom, [
PasswordlessPreBuiltUI,
]).map((route) => route.props),
{
path: "*",
element: <AppRoutes />,
},
]);
The router differences vs the tutorial are taken from the issue detailed here https://github.com/supertokens/supertokens-auth-react/issues/581.rp_st
11/19/2023, 8:00 PMrp_st
11/19/2023, 8:01 PMnpx create-supertokens-app@latest
) and see the diff between the generated app and yours.drifter2412
11/20/2023, 9:35 AMreact-router
being used is 6.2 vs the latest of 6.19 and therefore the use of BrowserRouter
vs createBrowserRouter
that was introduced in 6.4 which the latter is advised in the react-router-dom docs.
Reading through the docs I wonder if it's potentially because the component is created via the element
prop and rendered/reused when the route matches? I've not looked into the internals of the getSuperTokensRoutesForReactRouterDom
yet to see what it's exporting but does that sound like a reasonable theory?rp_st
11/20/2023, 9:37 AMrp_st
11/20/2023, 9:38 AMcreateBrowserRouter
ik_xyz
04/24/2024, 8:58 PM