wise-white
wise-white15mo ago

AuthPage does not handle any errors

Does the default AuthPage do any error handling by default ? I return an error in my authProvider login() function like this:
return {
success: false,
// error: new Error("Invalid email or password"), // first example in docs I saw
error: {
name: `Could not log in`, // second example
message: String((error as any)?.message || error || `Error`)
}
};
return {
success: false,
// error: new Error("Invalid email or password"), // first example in docs I saw
error: {
name: `Could not log in`, // second example
message: String((error as any)?.message || error || `Error`)
}
};
But the error does not appear on screen. To show the errors to the user is it required to swizzle this component ? I'm using the headless UI mode. Are the errors shown through notificationProvider ?
4 Replies
kapa.ai
kapa.ai15mo ago
Hey @rhengles! I'm the kapa.ai support bot. I've searched through the docs to try to answer your question. :wave: ---------------------- Yes, the default <AuthPage> handles error notifications automatically. When you return an error in your authProvider's login() function, refine will display an error notification. In your case, you're returning an error object with name and message properties:
return {
success: false,
error: {
name: `Could not log in`,
message: String((error as any)?.message || error || `Error`)
}
};
return {
success: false,
error: {
name: `Could not log in`,
message: String((error as any)?.message || error || `Error`)
}
};
Refine will automatically display an error notification with the provided name and message properties when the login method resolves the Promise with success: false source (https://refine.dev/docs/tutorial/understanding-authprovider/create-authprovider). You don't need to swizzle the component to show errors to the user, as the errors are shown through the notificationProvider by default. ----------------------
kapa.ai
kapa.ai15mo ago
<@246421183484919808> kapa.ai is still learning and improving, please let us how it did by reacting below
wise-white
wise-white15mo ago
that's impressive !
xenial-black
xenial-black15mo ago
yes to able to show errors require notificationProvider