amigoscode / full-stack-professional

https://amigoscode.com/courses/full-stack-professional
435 stars 205 forks source link

Create Customer Service (Angular - Fetch All Customers) #19

Open hazartilirot opened 1 year ago

hazartilirot commented 1 year ago

Actually, the solution shown in the video is incorrect since we have protected the route /api/v1/customers

We need to add a token each time we request. There should be something like the following:

findAll(): Observable<CustomerDto[]> {
        return this.http.get<CustomerDto[]>(
            "http://localhost:8080/api/v1/customers", {
                headers: new HttpHeaders({
                    "Authorization": `Bearer ${localStorage.getItem("token")}`
                })
            }
        );
    }
hazartilirot commented 1 year ago

Well, the fellow grabs the token and hardcodes it into the GET request - which is absolutely unnecessary. I set 60 minutes for a token to be valid.

It's the first time I watch a course with Angular. What a pity the fellow doesn't explain it wait.... you feel like you're a kind of a parrot that is supposed to repeat after him. I'm pretty much positive, there must be a kind of interception to include our token to all httpClient request.... why bother?