The ability to reply to discussions is limited to PRO members. Want to join in the discussion? Click here to subscribe now.

Client Setup for JWT Authentication

Client Setup for JWT Authentication

3:33
Creating a basic Angular application to access the random users resource. Also setting up CORS on the node server to enable the resource sharing across different domains (ports in our case).
Watch this lesson now
Avatar
egghead.io

Creating a basic Angular application to access the random users resource. Also setting up CORS on the node server to enable the resource sharing across different domains (ports in our case).

Avatar
Chris

In the video Kent used a http-server in his public folder to launch his application. Is there a place in docs that explains if that is the best practice in using this method?

Avatar
Kent C.

http-server is a node module that just serves up a directory as static files. I would not recommend using tool approach in production. Look into static file server solutions. One thing that I've done in the past that was really easy was use an amazon s3 bucket to host my frontend code. Or you could use firebase hosting, or github pages hosting, or a host of other options.

In reply to Chris
Avatar
Jonathan

I am following the series on JWT and everything is great until I run http-server (as you do) in the /public folder. Instead of it working like it did for you, I get "zsh: command not found: http-server". I already blew everything away once and started from scratch so I am pretty sure I haven't missed a step.

I started from an empty webstorm (actually, phpStorm) project just like you did and I have installed everything just as you did.

In reply to Kent C.
Avatar
Joel

I suspect the http-server node package needs to be installed:

npm install -g http-server

In reply to Jonathan
Avatar
Jonathan

Thanks, Joel. That worked and the site launched.

In reply to Joel
Avatar
Kody

I am getting a TypeError: Cannot read property 'then' of undefined for the RandomUserFactory.getUser().then

Avatar
Kent C.

Make sure that the getUser function is returning the promise created by $http. Like so:

return $http.get(API_URL + '/random-user');

In reply to Kody
Avatar
Robert

i am getting undefined for req.body.username. followed the same steps. any idea

Avatar
Lars Rye Jeppesen

I find it helpful to use a Docker container with an NgInx instance.

Yes, you have to learn about Docker but it is so awesome that it will be worth your while.

I always spin up a number of Docker containers as part of my development proces, it's imho invaluable.

In reply to Chris
Avatar
Jasna

Took a little while to figure out why I was still getting a CORS error. Realized it's important to call cors() before defining any routes. :)

Avatar
Sina

Hi, in my case everything works fine, except I am only able to click the button once and get the result. Any more clicks will not get any new random user!!! Any idea how to solve this??!

HEY, QUICK QUESTION!
Joel's Head
Why are we asking?