You need to call Moralis start

Hey. I get an error “You need to call Moralis start with appId before using Moralis”. I tried to use useEffect with isInitialized but i didnt work for this component. What should i do to get rid of this error? I use isInitialized in other components and they all work fine.
My goal is if the current user is the owner of contract, it could see the tab and its content otherwise couldnt.



const Interaction = () => {
  const [key, setKey] = useState('');
  const { Moralis, isInitialized, user, logout } = useMoralis();
  const owner = contract_address;

  const address = () => {
    return Moralis.User.current().get("ethAddress");
  }

  useEffect(() => {
    if (isInitialized) {
      address();
    }
  }, [isInitialized]);

  return (
    <div className='container'>
      <Tabs
        variant='tabs'
        id="controlled-tab-example"
        activeKey={key}
        onSelect={(k) => setKey(k)}
        className="container col-md-7"
      >
        
        {address() == owner.toLowerCase() && (
          <Tab eventKey="addTeacher" title="Öğretmen Ekle">
            <h1>as</h1>
          </Tab>)
        }
      </Tabs>
    </div>
  )
}

export default Interaction```

Did you set the serverUrl and appId?

yes i did. All the other pages works fine.

const APP_ID = "x";
const SERVER_URL = "x";

const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
    <MoralisProvider appId={APP_ID} serverUrl={SERVER_URL}>
        <ChakraProvider>
            
            <App />
            
        </ChakraProvider>
    </MoralisProvider>
);

You are using that component in App?

It declared as a route like all other components

<Route path="/interact" element={<Interaction/>}/>,

What happens if you comment this part?

it returns false and still gives error. Because this comparison is case sensitive. I transform both of the addresses toLowercase to get healhty comparison.

I mean that it is called separately, not in useEffect

1 Like

I think i solved it. I changed my address() funtion to async function. It solved the problem.

async function address () => {
    return Moralis.User.current().get("ethAddress").toLowerCase();
  }

Still gives error. Changing function to async function solves. Thank you for your help again.

1 Like