'Building a service to display a user icon with photo in Typescript and React

Many thanks for taking a look at my question, I'm new to coding so forgive me if this is simple!

I'm trying to build a service that basically uses an API to grab a user image to display in my navbar when the user is logged in.

I only need help with building the service. Essentially there will be like this:

const getAvatar = {
    Get:

        const response = await fetch(url);
        return response.json();
    },

So the API call will be in the fetch I believe with a token, but where do I put the token? I also know I need to use the React useAuth hook but i'm not exactly sure where



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source