bytesbay / web3-token

Web3 Token is a new way to authenticate users in a hybrid dApps using signed messages. Implementation of EIP-4361.
380 stars 50 forks source link

Test signing server-side #21

Closed Drarig29 closed 2 years ago

Drarig29 commented 2 years ago

I'm trying to run unit tests for my API on the server-side. But I get:

window is not defined

https://github.com/bytesbay/web3-token/blob/a77579931a606f06239b9f06021a8b587f749cd9/src/lib/sign/sign.js#L106-L108

I believe you tried to check if the window object exists here with the optional chaining operator.

But it doesn't work like that. You should check with typeof window === 'undefined' instead.

If you do that, the lib will entirely work both on Node.js and in the browser.