From 08a3708300443de712aa7c4612ca49190e21127f Mon Sep 17 00:00:00 2001 From: shayan khaleghparast Date: Tue, 18 Jun 2024 15:22:20 +0800 Subject: [PATCH 1/2] chore: return error in useAuthData response --- src/base/use-mutation.tsx | 2 +- src/context/auth-context.tsx | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/base/use-mutation.tsx b/src/base/use-mutation.tsx index 42bdec7..03780b3 100644 --- a/src/base/use-mutation.tsx +++ b/src/base/use-mutation.tsx @@ -11,7 +11,7 @@ export type AugmentedMutationResult = UseMutatio export type AugmentedMutationOptions = { name: T; bypassAuth?: boolean; -} & UseMutationOptions, TSocketError, TSocketRequestPayload>; +} & UseMutationOptions, TSocketError['error'], TSocketRequestPayload>; export const useMutation = ({ name, diff --git a/src/context/auth-context.tsx b/src/context/auth-context.tsx index 970a494..1cdff1d 100644 --- a/src/context/auth-context.tsx +++ b/src/context/auth-context.tsx @@ -3,6 +3,7 @@ import { URLUtils } from '@deriv-com/utils'; import { useAuthorize } from '../api/mutation/use-authorize'; import { useAppData } from '../base'; import Cookies from 'js-cookie'; +import { TSocketError } from '../types/api.types'; type AuthData = { activeLoginid: string; @@ -11,6 +12,7 @@ type AuthData = { switchAccount: (loginid: string) => void; appendAccountCookie: (loginid: string, token: string) => void; logout: () => void; + error: TSocketError<"authorize">['error'] | null; }; export const AuthDataContext = createContext(null); @@ -23,7 +25,8 @@ export const AuthDataProvider = ({ children }: AuthDataProviderProps) => { const { activeLoginid, setActiveLoginid } = useAppData(); const { loginInfo, paramsToDelete } = URLUtils.getLoginInfoFromURL(); - const { data, mutate, isSuccess } = useAuthorize(); + const { data, mutate, isSuccess, error } = useAuthorize(); + const accountsList: Record = JSON.parse(Cookies.get('accountsList') ?? '{}'); @@ -101,6 +104,7 @@ export const AuthDataProvider = ({ children }: AuthDataProviderProps) => { const value = useMemo( () => ({ + error, activeLoginid, isAuthorizing, switchAccount, @@ -108,7 +112,7 @@ export const AuthDataProvider = ({ children }: AuthDataProviderProps) => { logout, isAuthorized, }), - [activeLoginid, isSuccess] + [activeLoginid, isSuccess, error] ); return {children}; From b89a67423ee2972a9dee49799778479f16083a4f Mon Sep 17 00:00:00 2001 From: shayan khaleghparast Date: Tue, 18 Jun 2024 15:39:34 +0800 Subject: [PATCH 2/2] chore: added status to the useAuthData response --- src/context/auth-context.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/context/auth-context.tsx b/src/context/auth-context.tsx index 1cdff1d..87ddd82 100644 --- a/src/context/auth-context.tsx +++ b/src/context/auth-context.tsx @@ -25,7 +25,7 @@ export const AuthDataProvider = ({ children }: AuthDataProviderProps) => { const { activeLoginid, setActiveLoginid } = useAppData(); const { loginInfo, paramsToDelete } = URLUtils.getLoginInfoFromURL(); - const { data, mutate, isSuccess, error } = useAuthorize(); + const { data, mutate, isSuccess, error, status } = useAuthorize(); const accountsList: Record = JSON.parse(Cookies.get('accountsList') ?? '{}'); @@ -104,6 +104,7 @@ export const AuthDataProvider = ({ children }: AuthDataProviderProps) => { const value = useMemo( () => ({ + status, error, activeLoginid, isAuthorizing, @@ -112,7 +113,7 @@ export const AuthDataProvider = ({ children }: AuthDataProviderProps) => { logout, isAuthorized, }), - [activeLoginid, isSuccess, error] + [activeLoginid, isSuccess, error,status] ); return {children};