0
votes
  1. I used Angular CLI to generate an app.
  2. Ran "npm install angular2-jwt" in the terminal
  3. Added the script reference to angular-cli.json:

    "scripts":[
       ...
         "../node_modules/angular2-jwt/angular2-jwt.js"
       ...
     ]    
    
  4. Ran "ng serve" No problems so far

  5. But if I browse to http://localhost:4200 I get:
    caught ReferenceError: require is not defined at scripts.bundle.js:224 (anonymous) @ scripts.bundle.js:224

enter image description here

I don't want to keep implementing angular2-JWT with this error around. How can I fix this?

1

1 Answers

0
votes

I couldn't find an answer, and actually there's an issue open at Github about this, unresolved.

So i found this manual implementation of JWT authentication for the client

The idea is just to retrieve the token from the server, store it in the local storage, and then send it as a header in each request.