Replies: 5 comments
-
Did you solve your problems? I am also stuck in same problems. |
Beta Was this translation helpful? Give feedback.
-
Any update on this ?? is anyone going to take care of this ?? @balazsorban44 |
Beta Was this translation helpful? Give feedback.
-
Having same problem does anyone have any updates concerning this issue ? |
Beta Was this translation helpful? Give feedback.
-
@Zakisb @PrabeenGautam @AmineOussi any solutions? |
Beta Was this translation helpful? Give feedback.
-
Hello, I was having a similar issue, but I just wanted to display the error caught on the API on a toaster and I came across this solution: Catch the error from the API in the signIn callback function and encode it in the URI, see the code snippet below: catch (error: Error | any) {
return `/login?error=${encodeURIComponent(
error. response?.data?.message || "Sign-in failed"
)}`;
} This is how the complete signIn function looks: callbacks: {
async signIn({ user, account }) {
try {
if (account && account.provider !== "credentials") {
const res = await Axios.post(`${baseUrl}/auth/auth, {
provider: account.provider,
email: user.email,
name: user.name,
avatar: user.image,
});
//more logic
}
return true;
} catch (error: Error | any) {
return `/login?error=${encodeURIComponent(
error. response?.data?.message || "Sign-in failed"
)}`;
}
},
} To show it in the frontend get the error message from the 'error' param we encoded in the previous snippet, in this case, I use the useEffect to show the toaster export function LoginPage() {
const errorParam = param.get("error");
useEffect(() => {
if (errorParam) {
//Handle the error as you wish here
toast({
variant: "destructive",
title: "Login Failed",
//Don't forget to decode the error to show it as a string
description: decodeURIComponent(errorParam as string),
});
}
}, [errorParam, toast]);
return {
//render some code
}
} Remember you can play with the error message here to show more user oriented error messages: catch (error: Error | any) {
return `/login?error=${encodeURIComponent(
error. response?.data?.message === "Some server oriented error message" ? "Proper error for user" : error. response?.data?.message || "Sign-in failed"
)}`;
} Hope it helps! |
Beta Was this translation helpful? Give feedback.
-
Question 💬
I'm confused. i've been trying to wrap my head around this but still didn't find any solution. in my web app i have a sign up page. what i'd like to do is when the user sign up with his google account , check in my database if the email already exists. if it does then return 409 error. this is where i'm having trouble, i'd like if the response returned is 409 then display an error in my sign up component of "Email already exists". how do i achieve that ? here's my code. note that i'm using next 13.4 and next-auth 4
How to reproduce ☕️
My component
My sign next auth api file
Contributing 🙌🏽
Yes, I am willing to help answer this question in a PR
Beta Was this translation helpful? Give feedback.
All reactions