How can I customize useRegister onSuccess error toast notification message?
This is the refine V4 source code for useRegister hook. There is error handling, which by default throws up a popup with the error message.
How can I customize the popup message?
Now this error message comes from the backend:
18 Replies
Hey @mikusjozsef! I'm the kapa.ai support bot. I've searched through the docs to try to answer your question. :wave:
----------------------
To customize the error toast notification message in the
useRegister
hook, you can modify the buildNotification
function that is called when an error occurs. However, the provided extracts do not include the buildNotification
function or any information about customizing the error notification in the useRegister
hook.
You can refer to the refine documentation (https://refine.dev/docs) for more information on customizing notifications. If you need further assistance, please provide more information or code related to the buildNotification
function or the useRegister
hook.
----------------------Overview | refine
What is refine?
<@649975248107733013> kapa.ai is still learning and improving, please let us how it did by reacting below
optimistic-gold•2y ago
when you return
error
object from authProvider.register
function, popup will open.
quickest-silverOP•2y ago
@alicanerdurmaz No, it's not working. I try it.
graphql.request catches the error I think
conservative-teal•2y ago
Are you trying in
useRegister
hook or authProvider?quickest-silverOP•2y ago
@salihozdemir

quickest-silverOP•2y ago
The "Something went wrong!" message never appears. Instead, the other toast pops up
optimistic-gold•2y ago
probably you need to wrap your
request
to try catchquickest-silverOP•2y ago
@alicanerdurmaz
Yes, I tried. But then the check method runs and redirects me to the login
and one more thing. The try - catch check runs into catch, but useRegister mutate runs into onSuccess function instead of the onError
conservative-teal•2y ago
check
method works when user is authenticate. Can you explain in detail how the application should behave?quickest-silverOP•2y ago
@salihozdemir The check method was my fault, sorry 🙂
conservative-teal•2y ago
This is the expected behavior with v4, because we don't return
Promise.reject()
anymore. You can use data.success
to handle it.
You can check out our example: https://github.com/refinedev/refine/blob/next/examples/auth-chakra-ui/src/App.tsxquickest-silverOP•2y ago
yeah, but I can't display custom data if data has error, because the useRegister will catch it
optimistic-gold•2y ago
is this not work for you ?
quickest-silverOP•2y ago
Thanks, the custom error message is working now. But, now the onSuccess callback is fired instead of the onError then if there is an error.
conservative-teal•2y ago
It's a expected behavior with v4. You need to handle errors like below:
quickest-silverOP•2y ago
@salihozdemir Thank you, it's working now 🙂 You guys are the best