angular2-jwt: Cannot read property 'decode' of undefined

Hi,

I’m getting this error in ionic2. Cannot read property ‘decode’ of undefined.

When debugging, I find my token is read correctly from Storage, but when transpiled to JS, during the check of the Base64 encoding of parts[1], the Base64 object is missing a property.

TS: (line 179) export class JwtHelper {


  public urlBase64Decode(str: string): string {
    let output = str.replace(/-/g, '+').replace(/_/g, '/');
    switch (output.length % 4) {
      case 0: { break; }
      case 2: { output += '=='; break; }
      case 3: { output += '='; break; }
      default: {
        throw 'Illegal base64url string!';
      }
    }
    // This does not use btoa because it does not support unicode and the various fixes were... wonky.
    return Base64.decode(output);
  }

JS

var JwtHelper = (function () {
    function JwtHelper() {
    }
    JwtHelper.prototype.urlBase64Decode = function (str) {
        var output = str.replace(/-/g, '+').replace(/_/g, '/');
        switch (output.length % 4) {
            case 0: {
                break;
            }
            case 2: {
                output += '==';
                break;
            }
            case 3: {
                output += '=';
                break;
            }
            default: {
                throw 'Illegal base64url string!';
            }
        }
        // This does not use btoa because it does not support unicode and the various fixes were... wonky.
        return js_base64_1.Base64.decode(output);
    };

screenshot from 2016-10-09 00-23-02

So the result is that a property cannot be read. And I can’t send a header on a get request.

I’m using ionic serve -l to do the build.

Hope you guys have a suggestion, cheers!

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 13
  • Comments: 16 (5 by maintainers)

Most upvoted comments

after install angular2-jwt@0.1.23 fixed that issue

Ah. I am not an Ionic user, and I don’t use rollup. If I had to guess, it’s a matter of declaring the dependency in a way ionic can find it, same as systemjs. If you had to tell it about angular2-jwt, then you also need to tell it about js-base64.

Given the problems everyone seems to be having with the dependency, I might just copy the code in explicitly or find another solution.