Client Setup for JWT Authentication

Share this video with your friends

Send Tweet

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).

Chris
Chris
~ 10 years ago

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?

Kent C. Dodds
Kent C. Dodds(instructor)
~ 10 years ago

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.

Jonathan
Jonathan
~ 10 years ago

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.

Joel Hooks
Joel Hooks
~ 10 years ago

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

npm install -g http-server

Jonathan
Jonathan
~ 10 years ago

Thanks, Joel. That worked and the site launched.

Kody
Kody
~ 10 years ago

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

Kent C. Dodds
Kent C. Dodds(instructor)
~ 10 years ago

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

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

Robert
Robert
~ 9 years ago

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

Lars Rye Jeppesen
Lars Rye Jeppesen
~ 9 years ago

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.

Jasna
Jasna
~ 9 years ago

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. :)

Sina
Sina
~ 8 years ago

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??!