obabichev / react-token-auth

84 stars 22 forks source link

JSON.parse: unexpected non-whitespace character after JSON data on jwtExp #27

Open VA1992 opened 2 years ago

VA1992 commented 2 years ago

On the version 2.3.8 I'm experiencing an issue with the jwtExp function.

unexpected non-whitespace character after JSON data at line 1 column 117 of the JSON data.

Rolling back to 2.3.6 fix the issue.

liederivative commented 1 year ago

const middlePart = Base64.decode(token.split('.')[1]); <-- here a whitespace is included.

the issue here is in the Base64.decode function, for some reason is adding a whitespace when decoding the string. A possible solution could be changing the decoder to use atob? it will save some time debugging the current implementation for the decoder.

file location: src/utils/base64.js Method: decode

Patch:

var Base64 = {
     .....
     // replace current decode function 
    // public method for decoding
    decode: function (input) {
         return decodeURIComponent(atob(input));
    }
 }
alex-borisova commented 1 year ago

Hello guys! What is about this issue? I have the same:

SyntaxError: Unexpected non-whitespace character after JSON at position 5112 at JSON.parse () at jwtExp (isTokenExpired.js:17:1) at exports.isTokenExpired (isTokenExpired.js:6:1) at createAuthProvider.js:72:1 at step (createAuthProvider.js:33:1) at Object.next (createAuthProvider.js:14:1) at createAuthProvider.js:8:1 at new Promise ()