react-token-auth icon indicating copy to clipboard operation
react-token-auth copied to clipboard

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

Open VA1992 opened this issue 2 years ago • 2 comments

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.

VA1992 avatar Mar 24 '22 19:03 VA1992

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));
    }
 }

liederivative avatar Nov 20 '22 14:11 liederivative

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 ()

alex-borisova avatar Mar 02 '23 09:03 alex-borisova