rainbowkit
rainbowkit copied to clipboard
[bug] createMessage from createAuthenticationAdapter can't be async
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
Any idea how to solve this? Got exactly the same problem on my side :(
Out of interest, do you have a concrete example of what you need access to asynchronously?
Couldn't you use .then().catch()
instead of async/await in this case?
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?
@nickbytes please re-open this issue. It's not resolved
I have a related qualm - the
createMessage
function shouldn't need to be asynchronous, butgetNonce
needs to be able to accept parameters (like theaddress
andchainId
)...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