[SOLVED] Error: Service functions is not available

The code is as it is in youtube tutorial of Moralis. I am getting this error because of getMoralisAuth(). Also I have tried to import it from β€œ@moralisweb3/client-firebase-auth” and @moralisweb3/client-firebase-auth-utils, still not working.

import { useState } from "react";

import { initializeApp } from "firebase/app";

import { getMoralisAuth } from "@moralisweb3/client-firebase-auth-utils";

// import { getMoralisAuth } from "@moralisweb3/client-firebase-auth";

import { signInWithMoralis } from "@moralisweb3/client-firebase-evm-auth";

import { getAuth } from "@firebase/auth";

const firebaseConfig = {
//confidentials
};

const app = initializeApp(firebaseConfig);

const moralisAuth = getMoralisAuth(app);

const auth = getAuth(app);

function App() {

  const [user, setUser] = useState(null);

  async function login() {

    const res = await signInWithMoralis(moralisAuth);

    setUser(res.credentials.user.uid);

  }

  async function logout() {

    await auth.signOut();

    setUser(null);

  }

  return (

    <div className="App">

      <header className="App-header">

        <p>Firebase Moralis Auth Extension πŸ”</p>

        {!user ? (

          <div style={{ cursor: "pointer" }} onClick={login}>

            Login

          </div>

        ) : (

          <>

            <p>User:{user}</p>

            <div style={{ cursor: "pointer" }} onClick={logout}>

              Logout

            </div>

          </>

        )}

      </header>

    </div>

  );

}

export default App;

Hi @anand_jaat

Try with this code. I defined functions using getFunctions and used it along with getMoralisAuth function. This should fix the error related to service fucntions

// new import
import { getFunctions } from "firebase/functions";

const app = initializeApp(firebaseConfig);
const auth = getAuth(app);
const functions = getFunctions(app);

function App() {
  const [user, setUser] = useState(null);

  async function login() {
    const moralisAuth = getMoralisAuth(app, {
      auth,
      functions,
    });
    const res = await signInWithMoralis(moralisAuth);

    setUser(res.credentials.user.uid);
  }

  async function logout() {
    await auth.signOut();
    setUser(null);
  }

  return (
    <div className="App">
      <header className="App-header">
        <p>Firebase Moralis Auth Extension πŸ”</p>

        {!user ? (
          <div style={{ cursor: "pointer" }} onClick={login}>
            Login
          </div>
        ) : (
          <>
            <p>User:{user}</p>

            <div style={{ cursor: "pointer" }} onClick={logout}>
              Logout
            </div>
          </>
        )}
      </header>
    </div>
  );
}

export default App;
2 Likes

yeahhhh it worked thanks man

1 Like