angular2-jwt icon indicating copy to clipboard operation
angular2-jwt copied to clipboard

1.0.0 and 1.0.0-beta10, Fix for ReferenceError: URL is not defined

Open noumaans opened this issue 8 years ago • 6 comments

1.0.0-beta10 produces ReferenceError: URL is not defined.

Here is the proposed fix which seems to work for me in: jwt.interceptor.ts

const URL = require('url');

  // inside isWhitelistedDomain method
  isWhitelistedDomain(request: HttpRequest<any>): boolean {
    // const requestUrl = new URL(request.url);
    const requestUrl = URL.parse(request.url, false, true);
    ...

noumaans avatar Feb 19 '18 02:02 noumaans

I have an issue as well. This is a regression. I cannot use relative URL to my backend anymore. It throws an error:

TypeError: Failed to construct 'URL': Invalid URL

It was working fine on 1.0.0-beta.9. I will stick to the older version for now...

merlosy avatar Feb 22 '18 09:02 merlosy

@merlosy - please see #477 for relative URL discussion and possible security implications / workarounds.

noumaans avatar Feb 23 '18 16:02 noumaans

@chenkie I was hoping this fix would make it into 1.0.0. Can you please prioritize this (it's a one-liner). Thanks.

noumaans avatar Mar 11 '18 00:03 noumaans

@merlosy this isn't regression, it's simply a bug that was avoided by handling the error that throw. By removing the try catch in beta10 made this error showed up. In beta9 iswhitelisted is always true when your use "undefined" url (partial). Your solution seems to work @noomaans, you should create a pr.

Sambaja avatar Mar 11 '18 19:03 Sambaja

PR submitted.

noumaans avatar Mar 11 '18 20:03 noumaans

Thanks @chenkie

noumaans avatar Mar 15 '18 05:03 noumaans