Hi <@498057949541826571> User Metadata make the app fail. In a handler we call ``` console.log('t...
a

aquamarine2620

about 2 years ago
Hi @rp_st User Metadata make the app fail. In a handler we call
console.log('toto1')
  const session = await Session.getSession(req, res)
  const user = await EmailPassword.getUserById(session.getUserId())

  console.log('toto2')

  if (user === undefined) {
    next(new Error('INTERNAL_AUTHENTICATION_ERROR'))
    return
  }

  const { metadata } = await UserMetadata.getUserMetadata(user.id)
It fail after the second console.log and I think it's the UserMetadata that fails it. The init looks like this:
recipeList: [
    UserRoles.init(), // RBAC
    Session.init({ cookieDomain: `.${process.env.CLUSTER_HOST ?? ''}` }), // initializes session features
    UserMetadata.init()
  ]
Also when this occurs our pods logs this:
/app/node_modules/supertokens-node/lib/build/recipe/emailpassword/recipe.js:204
        throw new Error("Initialisation not done. Did you forget to call the SuperTokens.init function?");
              ^

Error: Initialisation not done. Did you forget to call the SuperTokens.init function?
    at Recipe.getInstanceOrThrowError (/app/node_modules/supertokens-node/lib/build/recipe/emailpassword/recipe.js:204:15)
    at Object.getUserById (/app/node_modules/supertokens-node/lib/build/recipe/emailpassword/index.js:72:33)
    at file:///app/dist/endpoints/save_shipping/post/controller.js:18:38
    at Generator.next (<anonymous>)
    at fulfilled (file:///app/dist/endpoints/save_shipping/post/controller.js:4:58)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
The issue I am having is how to check if the user is logged in and show them another navbar instead ...
k

kiesker

over 2 years ago
The issue I am having is how to check if the user is logged in and show them another navbar instead of the navbar for everyone who is not logged in. I am using supertokens to verify my users, this is my app.tsx. This is my code -
import { SuperTokensConfig, PreBuiltUIList } from './database/auth/supertoken';
import SuperTokens, { SuperTokensWrapper } from "supertokens-auth-react";
import { Routes, BrowserRouter as Router, Route } from "react-router-dom";
import { getSuperTokensRoutesForReactRouterDom } from 'supertokens-auth-react/ui'
import { SessionAuth, SessionContext } from "supertokens-auth-react/recipe/session"

//Components
import Navbar from './components/nav/Navbar';
import NavbarAuth from './components/nav/NavbarAuth';
//Free Routes
import Home from './routes/free/Home';
//Protected User Routes
import Profile from './routes/user/Profile';
//Protecte Admin Routes


SuperTokens.init(SuperTokensConfig);

function App() {
  //Here
  const check = SessionContext;
  return (
<SuperTokensWrapper>
  <div className='App app-container'>
    <Router>
      {check ? <Navbar /> : <NavbarAuth />}

      <Routes>
        {/* This shows the login UI on "/auth" route */}
        {getSuperTokensRoutesForReactRouterDom(require("react-router-dom"), PreBuiltUIList)}

        {/* Unprotected route */}
        <Route path="/" element={<Home />} />
        {/* Unprotected route */}

        {/* Protected route Users */}
        <Route
          path="/profile" element={
            /* This protects the "/" route so that it shows
          <Home /> only if the user is logged in.
          Else it redirects the user to "/auth" */
            <SessionAuth>
              <Profile />
            </SessionAuth>
          } />
        {/* Protected route Users */}

      </Routes>
    </Router>
  </div>
</SuperTokensWrapper>
  );
}

export default App;