ctx.error type

const handleSubmit = async (values: UserLoginValues) => {
await authClient.signIn.email(values, {
onError: (ctx) => {
console.log(ctx.error);
setError(getErrorMessage(ctx.error., "ua"));
setStatus("idle");
},
onRequest: () => {
setStatus("loading");
setError("");
},
onSuccess: () => {
setStatus("success");
router.push("/");
router.refresh();
},
});
};

console.log(ctx.error);
{
"message": "Invalid email or password",
"code": "INVALID_EMAIL_OR_PASSWORD",
"status": 401,
"statusText": "UNAUTHORIZED"
}
const handleSubmit = async (values: UserLoginValues) => {
await authClient.signIn.email(values, {
onError: (ctx) => {
console.log(ctx.error);
setError(getErrorMessage(ctx.error., "ua"));
setStatus("idle");
},
onRequest: () => {
setStatus("loading");
setError("");
},
onSuccess: () => {
setStatus("success");
router.push("/");
router.refresh();
},
});
};

console.log(ctx.error);
{
"message": "Invalid email or password",
"code": "INVALID_EMAIL_OR_PASSWORD",
"status": 401,
"statusText": "UNAUTHORIZED"
}
no auto-complete about code
No description
3 Replies
KiNFiSH
KiNFiSH6mo ago
you mean for this autocompletion
No description
bekacru
bekacru6mo ago
the docs are actually incorrect about the hook usage. OnError ctx is actually a BetterFetchError object. to access message and code you'll need to use ctx.error.error object
JohnyD
JohnyDOP6mo ago
yes, it is not in the autocomplete, but in fact it is

Did you find this page helpful?