Reputation: 1969
How can I generate JSon web token for a user who just login into the application in angular2/4 application
Upvotes: 1
Views: 402
Reputation: 86740
Actually there are number of way by using you can create JSON web token for your app, for example using btoa
approach , or using jwt.io
etc.
But Why to generate JSON web token ?
Generally JSON web token should be generated from back end side and which is safe also, so don't try this on client side.
Upvotes: 2
Reputation: 703
You can't generate web token from client side. Please use https://jwt.io/ to use it in your own server side language and use https://github.com/auth0/angular2-jwt this library to consume it.
Upvotes: 2
Reputation: 445
generating a token is a back-end side job and angularJs should just store it and send it to server to validate user data and basically generating it in front-end isn't a good idea cos you'r key will get in people's hand and they can generate tokens with it that server will validate it as True and it will make problems and error's for application.
Upvotes: 2