Skip to content

Commit

Permalink
Merge pull request #62 from deriv-com/shayan/add-error-to-useAuthData…
Browse files Browse the repository at this point in the history
…-response

Shayan/added error to useAuthData response
  • Loading branch information
shayan-deriv authored Jun 18, 2024
2 parents 92478f1 + b89a674 commit 13089fa
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/context/auth-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<AuthData | null>(null);
Expand All @@ -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, status } = useAuthorize();


const accountsList: Record<string, string> = JSON.parse(Cookies.get('accountsList') ?? '{}');

Expand Down Expand Up @@ -101,14 +104,16 @@ export const AuthDataProvider = ({ children }: AuthDataProviderProps) => {

const value = useMemo(
() => ({
status,
error,
activeLoginid,
isAuthorizing,
switchAccount,
appendAccountCookie,
logout,
isAuthorized,
}),
[activeLoginid, isSuccess]
[activeLoginid, isSuccess, error,status]
);

return <AuthDataContext.Provider value={value}>{children}</AuthDataContext.Provider>;
Expand Down

0 comments on commit 13089fa

Please sign in to comment.