ShabadLamba
ShabadLamba

Reputation: 31

Is there a module that allows you to generate JWT token in angular on client-side itself without actually having to make a request to server-side?

What I want to achieve is to be able to generate JWT token for signing in user to another website which has a readme page, the JWT token should be generated on the client-side itself which is in angular. I can't seem to able to find a module which would do that for me. Angular-jwt only handles jwt token doesn't generate them. I want to do something similar to below in angular on runtime to generate the redirect link with appropriate auth_token.

The code below is how it can be done in nodejs but is there a way to make this work in angular without having to make any request to the server side?

     import 'jsonwebtoken';
     function readMeLogin(){
     const sign = require('jsonwebtoken').sign;
     const user = {
       name: 'abc', //Actual user name
       email: '[email protected]', //Actual user email
       // User's API Key
       apiKey: 'key', //STATIC
      };
      const auth_token = sign(user, 'secretKey');//STATIC
      const readMeUrl = 'url.com'; //STATIC
      return '${readMeUrl}?auth_token=${auth_token}'
      };

Upvotes: 2

Views: 2048

Answers (0)

Related Questions