Fix SIWE chain-mismatch: switch wallet to Polygon 137 before sign-in and members-area unlock
This commit is contained in:
@@ -319,6 +319,9 @@
|
||||
const eth=await window.RMCWallet.pick();
|
||||
if(!eth){err.textContent='No wallet found in this browser. On a phone, open your wallet app (SafePal, Phantom, MetaMask, Trust, Coinbase…), go to its Browser or DApp tab, and type this page\'s address there — your wallet connects automatically.';return;}
|
||||
const accs=await eth.request({method:'eth_requestAccounts'});const account=accs[0];
|
||||
// Match the wallet's active chain to the SIWE message's Chain ID (137),
|
||||
// or the wallet rejects the signature ("chain ID does not match").
|
||||
try{await window.RMCWallet.ensureChain(eth);}catch(ce){err.textContent='Please switch your wallet to the Polygon network, then tap Connect again. (Your wallet blocks sign-in when it\'s on a different network.)';return;}
|
||||
const ch=await(await fetch('/api/public/msg-challenge',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({address:account})})).json();
|
||||
if(!ch.message)throw new Error(ch.error||'Could not start sign-in.');
|
||||
let hex='0x';for(const b of new TextEncoder().encode(ch.message))hex+=b.toString(16).padStart(2,'0');
|
||||
|
||||
Reference in New Issue
Block a user