You can use the angular2-jwt
package to handle JSON Web Tokens (JWT) in Angular applications. Here are the steps to use JWT in your Angular application using Typescript:
angular2-jwt
package using npm:25 chars2 lines
JwtModule
in your AppModule:index.ts393 chars18 lines
tokenGetter
function to retrieve the token from your storage, for example, localStorage:index.ts81 chars4 lines
JwtHelperService
to decode and verify the JWT:index.ts305 chars9 lines
jwtInterceptor
to add the token in the header of HTTP requests:index.ts310 chars12 lines
Now, all your HTTP requests will have the JWT token in the Authorization
header.
gistlibby LogSnag