rainbowkit icon indicating copy to clipboard operation
rainbowkit copied to clipboard

[bug] createMessage from createAuthenticationAdapter can't be async

Open Y0moo opened this issue 2 years ago • 3 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

RainbowKit Version

0.5.0

wagmi Version

0.6.4

Current Behavior

I'm creating a custom rainbow kit AuthProvider from docs. Here is an example from the docs:

createMessage: ({ nonce, address, chainId }) => {
    return new SiweMessage({
      domain: window.location.host,
      address,
      statement: 'Sign in with Ethereum to the app.',
      uri: window.location.origin,
      version: '1',
      chainId,
      nonce,
    });
  },

Expected Behavior

The problem is you can not generate the message asynchronously. I'd like to make an API request to let's say backend and from its response generate a Message:

createMessage: async ({ address, chainId }) => {
      const message = await apiPost('/auth/request-message', { address, chainId, network: 'evm' });
      return message;
},

But this will fail even if you add await and async to createMessage and getMessageBody because in the code permalink you have:

const message = authAdapter.createMessage({ address, chainId, nonce });

So adding there await should solve this problem

Steps To Reproduce

No response

Link to Minimal Reproducible Example (CodeSandbox, StackBlitz, etc.)

No response

Anything else?

No response

Y0moo avatar Aug 26 '22 09:08 Y0moo

Any idea how to solve this? Got exactly the same problem on my side :(

joakim-roos avatar Sep 05 '22 21:09 joakim-roos

Out of interest, do you have a concrete example of what you need access to asynchronously?

markdalgleish avatar Sep 08 '22 22:09 markdalgleish

Couldn't you use .then().catch() instead of async/await in this case?

mikefortney avatar Sep 13 '22 18:09 mikefortney

I have a related qualm - the createMessage function shouldn't need to be asynchronous, but getNonce needs to be able to accept parameters (like the address and chainId)...otherwise how would your nonce have any significance? Shouldn't your nonce be tied to an address on the backend?

brianyates avatar Sep 28 '22 11:09 brianyates

@nickbytes please re-open this issue. It's not resolved

Y0moo avatar Dec 25 '22 13:12 Y0moo

I have a related qualm - the createMessage function shouldn't need to be asynchronous, but getNonce needs to be able to accept parameters (like the address and chainId)...otherwise how would your nonce have any significance? Shouldn't your nonce be tied to an address on the backend?

Excactly, getNonce always get address undefined but it's needed in my auth process

HappySean2845 avatar Jan 29 '23 08:01 HappySean2845