Self hosted server acting up

So i have a self hosted server that is fully set up on ubuntu vps. The problem is, sometimes when people try to authenticate, i get auth failed error and this is the error log, any ideas? This doesn’t happen always, just sometimes.

check the message that was signed, is shouldn’t have an id and timestamp at the end

it could depend on the result returned by getServerTime cloud function

I’m sorry, but how do I check the signed message?

you will see it when you are asked to sign it with metamask, look at the end of the message

1 Like


Here is what the signed message looks like when the errors appear.

that is the expected message, you could try to add more logging server side to see why it fails sometimes

it could fail if it not validated in time for example

same code sometimes works fine and sometimes it doesn’t?

Yeah, it’s the same code, everything the same. Just sometimes it works sometimes it doesn’t

Can you check your server logs for any errors when this happens - it should be clearer on that side (compared to any errors in your app).

Sorry for a late response. The server logs are just full of this

info: Ran cloud function requestMessage for user undefined with:
  Input: {"address":"0x31262121e6db15c123fc1547a1b798f78f4a21ce","chain":1,"network":"evm"}
  Result: {"message":"defi.finance wants you to sign in with your Ethereum account:\n0x31262121E6dB15c123fC1547A1b798f78F4a21CE\n\nPlease sign this message to confirm your identity.\n\nURI: https://defi.finance\nVersion: 1\nChain ID: 1\nNonce: UMdNFp9QMGcA1N9md\nIssued At: 2022-12-09T02:07:41.577Z\nExpiration Time: 2023-01-01T00:00:00.000Z"} {"functionName":"requestMessage","params":{"address":"0x31262121e6db15c123fc1547a1b798f78f4a21ce","chain":1,"network":"evm"}}
warn: DeprecationWarning: auth.moralisEth is deprecated and will be removed in a future version. auth.moralisEth.enabled: true

This is in the logs folder

{"functionName":"getServerTime","level":"info","message":"Ran cloud function getServerTime for user undefined with:\n  Input: {}\n  Result: null","params":{},"timestamp":"2022-12-09T01:47:54.147Z"}
{"functionName":"requestMessage","level":"info","message":"Ran cloud function requestMessage for user undefined with:\n  Input: {\"address\":\"0x31262121e6db15c123fc1547a1b798f78f4a21ce\",\"chain\":1,\"network\":\"evm\"}\n  Result: {\"message\":\"defi.finance wants you to sign in with your Ethereum account:\\n0x31262121E6dB15c123fC1547A1b798f78F4a21CE\\n\\nPlease sign this message to confirm your identity.\\n\\nURI: https://defi.finance\\nVersion: 1\\nChain ID: 1\\nNonce: VTc5xKZAQ5S3qIywq\\nIssued At: 2022-12-09T01:47:54.623Z\\nExpiration Time: 2023-01-01T00:00:00.000Z\"}","params":{"address":"0x31262121e6db15c123fc1547a1b798f78f4a21ce","chain":1,"network":"evm"},"timestamp":"2022-12-09T01:47:54.680Z"}
{"level":"warn","message":"DeprecationWarning: auth.moralisEth is deprecated and will be removed in a future version. auth.moralisEth.enabled: true","timestamp":"2022-12-09T01:48:02.191Z"}
{"functionName":"getServerTime","level":"info","message":"Ran cloud function getServerTime for user undefined with:\n  Input: {}\n  Result: null","params":{},"timestamp":"2022-12-09T01:49:42.706Z"}
{"functionName":"requestMessage","level":"info","message":"Ran cloud function requestMessage for user undefined with:\n  Input: {\"address\":\"0x31262121e6db15c123fc1547a1b798f78f4a21ce\",\"chain\":1,\"network\":\"evm\"}\n  Result: {\"message\":\"defi.finance wants you to sign in with your Ethereum account:\\n0x31262121E6dB15c123fC1547A1b798f78F4a21CE\\n\\nPlease sign this message to confirm your identity.\\n\\nURI: https://defi.finance\\nVersion: 1\\nChain ID: 1\\nNonce: UvRbmaAUsTwAeDotG\\nIssued At: 2022-12-09T01:49:43.181Z\\nExpiration Time: 2023-01-01T00:00:00.000Z\"}","params":{"address":"0x31262121e6db15c123fc1547a1b798f78f4a21ce","chain":1,"network":"evm"},"timestamp":"2022-12-09T01:49:43.236Z"}
{"level":"warn","message":"DeprecationWarning: auth.moralisEth is deprecated and will be removed in a future version. auth.moralisEth.enabled: true","timestamp":"2022-12-09T01:49:47.493Z"}
{"functionName":"getServerTime","level":"info","message":"Ran cloud function getServerTime for user undefined with:\n  Input: {}\n  Result: null","params":{},"timestamp":"2022-12-09T01:53:04.013Z"}
{"functionName":"requestMessage","level":"info","message":"Ran cloud function requestMessage for user undefined with:\n  Input: {\"address\":\"0x31262121e6db15c123fc1547a1b798f78f4a21ce\",\"chain\":1,\"network\":\"evm\"}\n  Result: {\"message\":\"defi.finance wants you to sign in with your Ethereum account:\\n0x31262121E6dB15c123fC1547A1b798f78F4a21CE\\n\\nPlease sign this message to confirm your identity.\\n\\nURI: https://defi.finance\\nVersion: 1\\nChain ID: 1\\nNonce: eFQeCZlxhPUAp2KBh\\nIssued At: 2022-12-09T01:53:04.467Z\\nExpiration Time: 2023-01-01T00:00:00.000Z\"}","params":{"address":"0x31262121e6db15c123fc1547a1b798f78f4a21ce","chain":1,"network":"evm"},"timestamp":"2022-12-09T01:53:04.522Z"}
{"level":"warn","message":"DeprecationWarning: auth.moralisEth is deprecated and will be removed in a future version. auth.moralisEth.enabled: true","timestamp":"2022-12-09T01:53:10.441Z"}
{"functionName":"getServerTime","level":"info","message":"Ran cloud function getServerTime for user undefined with:\n  Input: {}\n  Result: null","params":{},"timestamp":"2022-12-09T01:53:37.377Z"}
{"functionName":"requestMessage","level":"info","message":"Ran cloud function requestMessage for user undefined with:\n  Input: {\"address\":\"0x31262121e6db15c123fc1547a1b798f78f4a21ce\",\"chain\":1,\"network\":\"evm\"}\n  Result: {\"message\":\"defi.finance wants you to sign in with your Ethereum account:\\n0x31262121E6dB15c123fC1547A1b798f78F4a21CE\\n\\nPlease sign this message to confirm your identity.\\n\\nURI: https://defi.finance\\nVersion: 1\\nChain ID: 1\\nNonce: 21a0Y8YeMZMaWPluv\\nIssued At: 2022-12-09T01:53:37.817Z\\nExpiration Time: 2023-01-01T00:00:00.000Z\"}","params":{"address":"0x31262121e6db15c123fc1547a1b798f78f4a21ce","chain":1,"network":"evm"},"timestamp":"2022-12-09T01:53:37.873Z"}
{"level":"warn","message":"DeprecationWarning: auth.moralisEth is deprecated and will be removed in a future version. auth.moralisEth.enabled: true","timestamp":"2022-12-09T01:53:42.863Z"}
{"functionName":"getServerTime","level":"info","message":"Ran cloud function getServerTime for user undefined with:\n  Input: {}\n  Result: null","params":{},"timestamp":"2022-12-09T02:04:30.634Z"}
{"functionName":"requestMessage","level":"info","message":"Ran cloud function requestMessage for user undefined with:\n  Input: {\"address\":\"0x31262121e6db15c123fc1547a1b798f78f4a21ce\",\"chain\":1,\"network\":\"evm\"}\n  Result: {\"message\":\"defi.finance wants you to sign in with your Ethereum account:\\n0x31262121E6dB15c123fC1547A1b798f78F4a21CE\\n\\nPlease sign this message to confirm your identity.\\n\\nURI: https://defi.finance\\nVersion: 1\\nChain ID: 1\\nNonce: H6MFyilMeVZih0vTM\\nIssued At: 2022-12-09T02:04:31.068Z\\nExpiration Time: 2023-01-01T00:00:00.000Z\"}","params":{"address":"0x31262121e6db15c123fc1547a1b798f78f4a21ce","chain":1,"network":"evm"},"timestamp":"2022-12-09T02:04:31.138Z"}
{"functionName":"getServerTime","level":"info","message":"Ran cloud function getServerTime for user undefined with:\n  Input: {}\n  Result: null","params":{},"timestamp":"2022-12-09T02:06:30.681Z"}
{"functionName":"requestMessage","level":"info","message":"Ran cloud function requestMessage for user undefined with:\n  Input: {\"address\":\"0x31262121e6db15c123fc1547a1b798f78f4a21ce\",\"chain\":1,\"network\":\"evm\"}\n  Result: {\"message\":\"defi.finance wants you to sign in with your Ethereum account:\\n0x31262121E6dB15c123fC1547A1b798f78F4a21CE\\n\\nPlease sign this message to confirm your identity.\\n\\nURI: https://defi.finance\\nVersion: 1\\nChain ID: 1\\nNonce: JJozdxPAywrLlwKFY\\nIssued At: 2022-12-09T02:06:31.140Z\\nExpiration Time: 2023-01-01T00:00:00.000Z\"}","params":{"address":"0x31262121e6db15c123fc1547a1b798f78f4a21ce","chain":1,"network":"evm"},"timestamp":"2022-12-09T02:06:31.197Z"}
{"functionName":"getServerTime","level":"info","message":"Ran cloud function getServerTime for user undefined with:\n  Input: {}\n  Result: null","params":{},"timestamp":"2022-12-09T02:07:40.530Z"}
{"functionName":"requestMessage","level":"info","message":"Ran cloud function requestMessage for user undefined with:\n  Input: {\"address\":\"0x31262121e6db15c123fc1547a1b798f78f4a21ce\",\"chain\":1,\"network\":\"evm\"}\n  Result: {\"message\":\"defi.finance wants you to sign in with your Ethereum account:\\n0x31262121E6dB15c123fC1547A1b798f78F4a21CE\\n\\nPlease sign this message to confirm your identity.\\n\\nURI: https://defi.finance\\nVersion: 1\\nChain ID: 1\\nNonce: UMdNFp9QMGcA1N9md\\nIssued At: 2022-12-09T02:07:41.577Z\\nExpiration Time: 2023-01-01T00:00:00.000Z\"}","params":{"address":"0x31262121e6db15c123fc1547a1b798f78f4a21ce","chain":1,"network":"evm"},"timestamp":"2022-12-09T02:07:41.632Z"}
{"level":"warn","message":"DeprecationWarning: auth.moralisEth is deprecated and will be removed in a future version. auth.moralisEth.enabled: true","timestamp":"2022-12-09T02:07:47.225Z"}
{"functionName":"getServerTime","level":"info","message":"Ran cloud function getServerTime for user undefined with:\n  Input: {}\n  Result: null","params":{},"timestamp":"2022-12-09T19:48:24.690Z"}
{"functionName":"requestMessage","level":"info","message":"Ran cloud function requestMessage for user undefined with:\n  Input: {\"address\":\"0xe8bb9a175fbe3170c7a5b1428294bb839841a909\",\"chain\":1,\"network\":\"evm\"}\n  Result: {\"message\":\"defi.finance wants you to sign in with your Ethereum account:\\n0xE8bb9A175fBe3170C7a5B1428294Bb839841A909\\n\\nPlease sign this message to confirm your identity.\\n\\nURI: https://defi.finance\\nVersion: 1\\nChain ID: 1\\nNonce: ugVjNGlGWqqayTxqn\\nIssued At: 2022-12-09T19:48:24.966Z\\nExpiration Time: 2023-01-01T00:00:00.000Z\"}","params":{"address":"0xe8bb9a175fbe3170c7a5b1428294bb839841a909","chain":1,"network":"evm"},"timestamp":"2022-12-09T19:48:25.022Z"}

Can you post your server’s request message code (inside src/auth/authService.ts).

Thanks for helping out. Here is the whole file.

import Moralis from 'moralis';

export interface RequestMessage {
  address: string;
  chain: string;
  networkType: string;
}

const DOMAIN = 'defi.finance';
const STATEMENT = 'Please sign this message to confirm your identity.';
const URI = 'https://defi.finance';
const EXPIRATION_TIME = '2023-01-01T00:00:00.000Z';
const TIMEOUT = 15;

export async function requestMessage({
  address,
  chain,
  networkType,
}: {
  address: string;
  chain: string;
  networkType: 'evm';
}) {
  const result = await Moralis.Auth.requestMessage({
    address,
    chain,
    networkType,
    domain: DOMAIN,
    statement: STATEMENT,
    uri: URI,
    expirationTime: EXPIRATION_TIME,
    timeout: TIMEOUT,
  });

  const { message } = result.toJSON();

  return message;
}

Can you repeat what is the issue?

Try increasing that timeout value. Are you able to reproduce the auth failed error yourself?

No, I cannot recreate it myself.

Some people sometimes get auth failed error when logging in

Still the same. No idea what causes this.

What is your new timeout? This is with a project using the Moralis Unity SDK?