Fetching data with authorisation token
I’m using auth.js with cognito and my backend requires the authorisation token to be present with every request. I’ve managed to get this working by using createServerData$ and then passing it to a generic GET function that will retrieve the token from the request. Is this the best way of doing this? I’m struggling to create a wrapper around createServerData.
I have a dashboard of components that each hit different endpoints, my thoughts were to have them handle their fetching themselves but it’s a lot of duplicate code with createServerData each time.
Has anyone else had a similar problem?
5 Replies
send us your
createServerData
function
show us your code ;DThis is one of the createServerData's
And then the generic get function I'm using to add the accessToken to the header
I'm definitely doing something wrong here 😂
which is the one that works?
It all works, Im just wondering if the way im going about it is the best practice for appending the accessToken to every request or whether ive set something up wrong architecturally
Ideally I want to cut down the lines of code required for each component that makes a request and just have simple get functions in the routeData, even if that means wrapping the createServerData but I couldnt manage to get a wrapper to work
This seems to be the usual way of doing it. Unless you want to make use of an axios instance. e.g