From 94eb85c732cb2e58df3862b06b6fe5ebe1924613 Mon Sep 17 00:00:00 2001 From: Mo8Faiz <149877763+Mo8Faiz@users.noreply.github.com> Date: Mon, 18 Aug 2025 20:07:38 +0530 Subject: [PATCH] improved error handling in login --- src/authProvider.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/authProvider.ts b/src/authProvider.ts index 55e109b..1bd1056 100644 --- a/src/authProvider.ts +++ b/src/authProvider.ts @@ -1,7 +1,7 @@ import { AuthBindings } from "@refinedev/core"; import { TOKEN_KEY, API_URL } from "./constants"; -import axios, { AxiosInstance } from "axios"; +import axios, { AxiosInstance,AxiosError } from "axios"; export const authProvider = (axiosInstance: AxiosInstance): AuthBindings => { return { @@ -17,10 +17,14 @@ export const authProvider = (axiosInstance: AxiosInstance): AuthBindings => { success: true, redirectTo: "/", }; - } catch (error: any) { + } catch (error: unknown) { //By this way Users will get a structured error instead of raw one. + const err = error as AxiosError<{ errors?: string[] }>; return { success: false, - error, + error: { + message: err.response?.data?.errors?.[0] || err.message, + name: "LoginError", + }, }; } },