truffle-box / react-uport-box

Truffle, Webpack, React, Redux boilerplate with routing and authentication via a UPort.
https://truffle-box.github.io/
MIT License
97 stars 27 forks source link

Error: JWT has expired #16

Open mokn opened 6 years ago

mokn commented 6 years ago

Was part of a hackathon a few months ago and we used the uport box to bootstrap the project. It was working then but not now. Trying to get this to work but continue receiving this error: Error: JWT has expired.

Code we had working 2 months ago was: export let uport = new Connect('TruffleBox');.

Project is at - https://github.com/micksabox/ethwaterloo2017

Any idea why this may be happening and how I can fix?

ToJen commented 6 years ago

I think that's still the same line in src/util/connectors.js. I have the same error, can't even login. I was at EthWaterloo too :)

ingcoders commented 6 years ago

This is due to clock on the device not being in sync.

ToJen commented 6 years ago

Thanks @ingcoders, in sync with what exactly?

mdtanrikulu commented 6 years ago

Problem is in given line for the used version of uport library: https://github.com/uport-project/uport-js/blob/e8803dc2b6f2bf4213ff188f1dd930cc01e4ba9a/src/JWT.js#L29

payload.exp timestamp has 10 char but, new Date().getTime() has 13. So even if payload.exp bigger than current timestamp, because of this character difference current time is always bigger. I think they solved this with their current version, but if you want to do quickfix this issue you can use simply;

Math.floor(new Date().getTime()/1000))

instead of

new Date().getTime()
wrannaman commented 6 years ago

I solved this by creating an app in uPort

  1. create an app in uport
  2. copy the code at the bottom under 'Click Here for your App Code'
  3. Change
    import { Connect } from 'uport-connect
    export let uport = new Connect('TruffleBox')
    export const web3 = uport.getWeb3()

    to

    
    import { Connect, SimpleSigner } from 'uport-connect'

export const uport = new Connect('Test Ap 1', { clientId: 'xxx', network: 'rinkeby', signer: SimpleSigner('xxx') }) export const web3 = uport.getWeb3()

ToJen commented 6 years ago

@wrannaman thanks man! can't believe i missed that haha

ToJen commented 6 years ago

@wrannaman where did you add the requestCredentials and attestCredentials functions?

ToJen commented 6 years ago

nvm it's in /src/user/ui/loginbutton/LoginButtonActions.js, at least for requestCredentials

kishorebhatia commented 6 years ago

@wrannaman trying to integrate uport-connect with our DApp and this was a life saver today (in the #EthDenver2018 hackathon)! Thanks a bunch!

Ejdems666 commented 6 years ago

I just updated the uport-connect package to current version 0.7.1 and it worked.