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
KiNFiSH3w ago
you mean for this autocompletion
No description
bekacru
bekacru3w 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
JohnyDOP3w ago
yes, it is not in the autocomplete, but in fact it is

Did you find this page helpful?