amaury1093 / login-with-metamask

Demo project for "One-click Login with Blockchain: A MetaMask Tutorial"
https://www.toptal.com/ethereum/one-click-login-flows-a-metamask-tutorial
MIT License
679 stars 294 forks source link

{error: "Signature verification failed"} #3

Closed ciumexan closed 5 years ago

ciumexan commented 6 years ago

Hello, From time to time i get this after login (if i login/logout for a few times) :

{error: "Signature verification failed"}

on the back-end i get this error in the console:

screen shot 2018-06-16 at 21 13 19

Then, on the frontend i see:

screen shot 2018-06-16 at 21 11 24

Here is my console on the frontend:

screen shot 2018-06-16 at 21 11 45

screen shot 2018-06-16 at 21 11 59

It has something to do with jwt token?

Can you tell mehow can i investigate where is the pb?

If i delete cookies on the app itself, I can login, but immediately throws that error...

I cannot figure why.

amaury1093 commented 6 years ago

Unfortunately I cannot reproduce, I just tried logging in and out 20 times, no errors.

Could you add the following lines at this place: https://github.com/amaurymartiny/login-with-metamask-demo/blob/master/backend/src/services/auth/controller.js#L48?

console.log('user', user);
console.log('msg', msg);
console.log('msgBuffer', msgBuffer.toString('hex'));
console.log('msgHash', msgHash.toString('hex'));
console.log('signatureBuffer', signatureBuffer.toString('hex'));
console.log('v', signatureParams.v);
console.log('s', signatureParams.s.toString('hex'));
console.log('r', signatureParams.r.toString('hex'));
console.log('publicKey', publicKey.toString('hex'));
console.log('addressBuffer', addressBuffer.toString('hex'));
console.log('address', address);
console.log('publicAddress', publicAddress);

and paste the logs in the backend. It will help me debug what went wrong with the signature verification.

ciumexan commented 6 years ago

This is my backend output 👍 https://pastebin.com/JEphQ90X

ciumexan commented 6 years ago

hello back did you had any chance on looking at it? I am still struggling with it, as i will need to use this with nextjs. if you need more info, i can provide you asap. thanks

amaury1093 commented 6 years ago

The backend logs look good.

Could you add one line in the backend code:

        console.log('user', user);
        console.log('msg', msg);
        console.log('signature', signature);
        console.log('msgBuffer', msgBuffer.toString('hex'));
        console.log('msgHash', msgHash.toString('hex'));
        console.log('signatureBuffer', signatureBuffer.toString('hex'));
        console.log('v', signatureParams.v);
        console.log('s', signatureParams.s.toString('hex'));
        console.log('r', signatureParams.r.toString('hex'));
        console.log('publicKey', publicKey.toString('hex'));
        console.log('addressBuffer', addressBuffer.toString('hex'));
        console.log('address', address);
        console.log('publicAddress', publicAddress);

And also, in the frontend, add this console.log at this line: https://github.com/amaurymartiny/login-with-metamask-demo/blob/master/frontend/src/Login/Login.js#L70-L71

          if (err) return reject(err);
          console.log(publicAddress, nonce, signature);
          return resolve({ publicAddress, signature });
ciumexan commented 6 years ago

got it. will do asap.

ciumexan commented 6 years ago

Here is the output: https://pastebin.com/T5wdVub0

ciumexan commented 6 years ago

This is What i get on the frontend:

screen shot 2018-06-26 at 14 25 21

and..

screen shot 2018-06-26 at 14 24 57
amaury1093 commented 6 years ago

Interesting, this looks like a different error. This may take some time to debug though, so let's both be patient :)

  1. When do the above error fire? On startup? When you click on the login button?
  2. Did you add the console.log(publicAddress, nonce, signature); on the frontend, as I described above? Does that log in the console?

Thanks.

amaury1093 commented 5 years ago

I'll close this. Please re-open if it's still reproducible.