question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Invalid token specified: Cannot read property 'replace' of undefined

See original GitHub issue

I get Invalid token specified: Cannot read property ‘replace’ of undefined:

Object.<anonymous> ../node_modules/jwt-decode/lib/index.js 9:0
Showing original source content from sourcemap
'use strict';
 var base64_url_decode = require('./base64_url_decode');
 function InvalidTokenError(message) {
  this.message = message;
}
 InvalidTokenError.prototype = new Error();
InvalidTokenError.prototype.name = 'InvalidTokenError';
 
module.exports = function(token, options) {
    if (typeof token !== 'string') {
      throw new InvalidTokenError('Invalid token specified');
    }

Can i get any help ASAP please?!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:16 (1 by maintainers)

github_iconTop GitHub Comments

7reactions
jyoti739commented, Mar 1, 2019

I had same problem as well, If you are login to the App and you did play with token in backend(postman). then token mismatch might happen so you take recent token from postman and add it to the localstorage in the browser, which was in undefined.

7reactions
Gloryofthe80scommented, Nov 16, 2018

In my case, I’m attempting to protect the client-side app against “corrupt” cookies (tokens that aren’t in JWT format) in the event a user messes with their cookies. In the moment I’m decoding, if the token can’t be parsed, the error thrown breaks the app, despite my attempt to catch.

export const isAccessTokenExpired = (): boolean => {
  if (!isAccessTokenSet()) {
    // if it doesn't exist, we'll also consider it expired
    return true;
  }

  // ensure it's actually JWT format
  try {
    jwt_decode(getAccessToken());
  } catch (error) {
    console.log('👾 invalid token format', error);
    return true;
  }

  const token = jwt_decode(getAccessToken());
  const { exp } = token;
  return Math.round(Date.now() / 1000) >= exp ? true : false;
};

Upon attempting to decode a non-JWT format value, the catch triggers, but the error still shows as Uncaught and breaks runtime:

👾 invalid token format InvalidTokenError {message: "Invalid token specified: Cannot read property 'replace' of undefined"}

Uncaught InvalidTokenError {message: "Invalid token specified: Cannot read property 'replace' of undefined"}
message: "Invalid token specified: Cannot read property 'replace' of undefined"
Read more comments on GitHub >

github_iconTop Results From Across the Web

Invalid token specified: Cannot read property 'replace' of ...
But for some reason it shows "InvalidTokenError: Invalid token specified: Cannot read property 'replace' of undefined" this error, I really need ...
Read more >
"Invalid token specified: Cannot read property 'replace ... - 8base
The auth variable that is imported from utils/auth. js is only used in the hosted login example. It works fine when I clone...
Read more >
Uipath Robot Error - Invalid token specified: Cannot read ...
Uipath Robot Error - Invalid token specified: Cannot read property 'replace' of undefined. This happens when: I log in into the virtual machine ......
Read more >
Issue logging into MS Teams with Guest account
This post has been split from "Invalid token specified: Cannot read property 'replace' of undefined” Im running into the same issue, ...
Read more >
[Vue warn]: Error in render function: "InvalidTokenError: Invalid ...
... Invalid token specified: Cannot read property 'replace' of undefined" ... “Copy the CLIENT ID and replace it with the value of ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found