fix message file upload #401
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The problem is in the createMessageWithFile method, which isn't properly including the user authentication when sending the file upload request.
Looking at your code, I can see that:
The axiosClient is being created with the app key and admin key in the headers
There's an interceptor using this.options.authAxiosMiddleware, but this isn't being properly applied when making the FormData POST request
Unlike other methods that use the GraphQL client (which has all middleware properly configured), the direct axios POST doesn't include the user authorization token
The solution is to explicitly get the authorization headers from the middleware and include them in the request. Here's what's happening and how to fix it:
The authAxiosMiddleware function in KanvasCore returns an object with the Authorization header
However, when making the FormData request, you're not including these headers in the POST request
You need to explicitly call the middleware to get the auth headers and add them to your request