Update auth
How to update details of a logged in user ? Is it possible to create a custom hook in auth provider ? Having the ability create a custom hook for an auth provider would be great. Currently, authProvider AuthBinding type doesnt have the option to plug in a custom hook.
Adding more context, havin a hook to update any field of a logged in user will be great. Lets say allowing the user to change his username or any other field with a hook would be great.
Currently, I can do so by getting the user from useGetIdentity hook.
But as we are persisting the user in the local storage I would have to update the local storage as well outside of the auth provider. Not a hassle as I can just create a custom hook for it but having the ability to fix all this up directly inside a hook will clean be clean.
30 Replies
Hi @haribo_mushi. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
Hmm, I don't know enough to give you a confident answer yet. However, you can refer to the refine documentation for more information on authentication and auth providers: refine documentation (https://refine.dev/docs).
----------------------
Note: you can ask me a follow up question by @ mentioning me again
:speech_balloon:
----------------------<@886127984711438378> kapa.ai is still learning and improving, please let us how it did by reacting below
stormy-gold•16mo ago
hey @kapa.ai I am adding deletebutton from refineantd to my show headerbutton props and after manually adding it, it fail to redirect me back to listing page. any ideao how to This wasnt the case when I didnt manually added DeleteButton in the headerbuttons prop. Any idea how to fix this ? I am guessing I have to passing it navigate function to its onSuccess props ?
Let me check the knowledge base for you. One moment! :books:
----------------------
Yes, you're on the right track. When you manually add the
DeleteButton
to the headerButtons
prop, you might need to pass the onSuccess
prop to handle the navigation after a successful delete action. You can use the useNavigation
hook from refine to achieve this.
Here's an example of how to add the DeleteButton
with the onSuccess
prop:
In this example, the onSuccess
prop is passed to the DeleteButton
, and it uses the navigate
function from the useNavigation
hook to navigate back to the listing page after a successful delete action.
----------------------
Note: you can ask me a follow up question by @ mentioning me again
:speech_balloon:
----------------------<@886127984711438378> kapa.ai is still learning and improving, please let us how it did by reacting below
stormy-gold•16mo ago
@kapa.ai i am using mutateAsync from useCustomMutation query for my photo edit upload. I am setting my content-type header to be multipart/form-data. However, after putting this request the problem is for my next requests onward it keeps on setting my content-type to this instead of application/json. I did set my axios instance defaul header to be application/json but it seems to be getting ignored all over
Let me check the knowledge base for you. One moment! :books:
----------------------
It seems like the issue is related to the axios instance headers being overridden after setting the
Content-Type
to multipart/form-data
. To fix this, you can create a new axios instance specifically for the file upload request, so it doesn't affect the default headers of your main axios instance.
Here's an example of how to create a new axios instance for the file upload request:
By using a separate axios instance for the file upload request, you can ensure that the default headers of your main axios instance remain unchanged.
----------------------
Note: you can ask me a follow up question by @ mentioning me again
:speech_balloon:
----------------------<@886127984711438378> kapa.ai is still learning and improving, please let us how it did by reacting below
stormy-gold•16mo ago
@kapa.ai is there not any other way around ?
Let me check the knowledge base for you. One moment! :books:
----------------------
Yes, there is another way to handle this issue without creating a separate axios instance. You can use an axios request interceptor to set the
Content-Type
header for specific requests and reset it back to application/json
for other requests.
Here's an example of how to use an axios request interceptor:
In this example, the interceptor checks if the request URL includes the file upload endpoint. If it does, it sets the Content-Type
header to multipart/form-data
. For all other requests, it sets the Content-Type
header back to application/json
. This way, you can ensure that the correct Content-Type
header is set for each request without affecting the default headers of your main axios instance.
----------------------
Note: you can ask me a follow up question by @ mentioning me again
:speech_balloon:
----------------------<@886127984711438378> kapa.ai is still learning and improving, please let us how it did by reacting below
stormy-gold•16mo ago
@kapa.ai
this is what it looks like it should only be setting on this one request but no. Why is such the case ?
Let me check the knowledge base for you. One moment! :books:
----------------------
It seems like you're trying to set the
Content-Type
header only for this specific request. However, it's not working as expected, and the header persists for other requests as well. The issue might be related to how you're passing the config
object to the mutateAsync
function.
To ensure that the Content-Type
header is set only for this specific request, you can try the following approach:
1. Make sure you're using the correct property name for passing the config object to the mutateAsync
function. It should be axiosConfig
instead of config
.
Here's the updated code snippet:
By using the correct property name axiosConfig
, you should be able to set the Content-Type
header only for this specific request without affecting other requests.
----------------------
Note: you can ask me a follow up question by @ mentioning me again
:speech_balloon:
----------------------<@886127984711438378> kapa.ai is still learning and improving, please let us how it did by reacting below
stormy-gold•16mo ago
@kapa.ai 'axiosConfig' does not exist in type 'useCustomMutationParams<PutAvatarAdminResponse,