full-stack-professional icon indicating copy to clipboard operation
full-stack-professional copied to clipboard

Create Customer Service (Angular - Fetch All Customers)

Open hazartilirot opened this issue 1 year ago • 1 comments

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 avatar May 19 '23 19:05 hazartilirot

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?

hazartilirot avatar May 19 '23 19:05 hazartilirot