[SOLVED] 403 unauthorised response from authenticate()

Just getting started with a new app - using the below React to Login with Metamask:

import { useMoralis } from "react-moralis";
import { useRouter } from "next/router";
import { useEffect } from "react";

export default function SignIn() {

  const { authenticate, isAuthenticated } = useMoralis();
  const router = useRouter();

  useEffect(() => {
    if (isAuthenticated) router.replace("/work/search");
  }, [isAuthenticated]);

  return (
    <div className="min-h-full flex items-center justify-center py-12 px-4 sm:px-6 lg:px-8">
      <Head>
        <title>Sign In - Worklink</title>
      </Head>
      <div className="max-w-md w-full space-y-8">
        <div>
          <h2 className="mt-6 text-center text-3xl font-extrabold text-gray-900">Sign in to your account</h2>
          <button className="mt-2 text-center text-sm text-gray-600"
            onClick={() =>
              authenticate({ signingMessage: "Authorize linking of your wallet" })
            }>
            Sign in with Metamask
          </button>
        </div>
      </div>
    </div>
  )
}

When testing in the browser, it opens Metamask and asks for authentication, but when agreeing the app won’t authenticate, returning a 403 response:

What version of Moralis sdk are you using?

I’m using

"moralis": "^1.5.4",
    "navbar": "^2.1.0",
    "react": "17.0.2",
    "react-dom": "17.0.2",
    "react-moralis": "^1.3.2",
    "next": "12.0.1",
    "postcss": "^8.4.8",

and the server is 0.0.359

What do you see in MetaMask when you have to sign the authentication message? It is only the message or also something more?

I get what looks like a standard Login request:

When I click ‘Sign’, the dialog closes. I can see the request in the network tab, but alas, unauthorised.

I don´t know if it helps but there are a few warnings in npm -

warn  - ./node_modules/moralis/lib/browser/Web3Connector/MagicWeb3Connector.js
Module not found: Can't resolve 'magic-sdk' in '/home/runner/Worklink/node_modules/moralis/lib/browser/Web3Connector'

./node_modules/moralis/lib/browser/Web3Connector/Web3AuthConnector.js
Module not found: Can't resolve '@web3auth/web3auth' in '/home/runner/Worklink/node_modules/moralis/lib/browser/Web3Connector'

Did you delete anything from the server database about users?

A brand new test server, untouched :grinning:

Can you try to update it?

I’ve updated and restarted the server using the green button on the admin:

But it still get the unauthorised response after signing Metamask.

Can you paste the server url?

Can you try with a different account too?

Ok. I deleted the server and booted a new one, and its working. Thanks for your assistance.

2 Likes