-
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
window.jwt_decode is undefined #755
Comments
look in their inde.html |
i don't see inde.html nor index.html file in this repo |
i see this line in index.html file. <script type="text/javascript" src="/node_modules/jwt-decode/build/jwt-decode.js"></script>But when I include that in my index.html And I am trying to import this file in vendor.browser.ts but I can't proceed because this library doesn't have .ts file Do you have any suggestion for this? |
hi @gdi2290 do you have any opinion? |
in custom-typings include declare module "jwt-decode" {
function decode(token: string): any;
namespace decode {} // notice how we have to create a namespace that is equal to the function we're assigning the export to
export = decode;
} then in vendor import 'jwt-decode'; then in your app import * as jwt_decode from 'jwt-decode';
let jwt = 'wat'; // your jwt
let result = jwt_decode(jwt);
console.log(result); |
hi @gdi2290 it works and when I debug 'let result=jwt_decode(jwt)' it actually calls the function from node_modules/jwt-decode. can you explain a little bit please? |
@gdi2290 the code is working it shows the error around this code. [default] /home/georgismall/Project/closetbox-new-admin/src/app/app.component.ts:11:29 But it works, any idea? |
@georgi-kovachev can you update the type definitions to declare module "jwt-decode" {
function decode(token: string): any;
namespace decode {} // notice how we have to create a namespace that is equal to the function we're assigning the export to
export = decode;
} there needs to be a |
Thanks it works. |
I'm not getting this to work. I still get It works if I change the type definition to this:
And remove this from the top of the file: |
is different from
the declare you have is saying jwt_decode is a global function while the other one is saying the type returned from the |
https://github.com/auth0-blog/angular2-authentication-sample
I took the code for above link and I am applying jwt related code to this project but I get this error.
browser_adapter.js:77 ORIGINAL EXCEPTION: TypeError: window.jwt_decode is not a function
And I included this code to custom-typings.d.ts
interface Window {
jwt_decode(jwt: string): any;
}
Any idea?
The text was updated successfully, but these errors were encountered: