diff --git a/package.json b/package.json index 44d4795..46197f3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "qapp-core", - "version": "1.0.16", + "version": "1.0.17", "description": "Qortal's core React library with global state, UI components, and utilities", "main": "dist/index.js", "module": "dist/index.mjs", diff --git a/src/hooks/useAuth.tsx b/src/hooks/useAuth.tsx index 45da031..5c93714 100644 --- a/src/hooks/useAuth.tsx +++ b/src/hooks/useAuth.tsx @@ -19,14 +19,18 @@ export type BalanceSetting = interval?: number; }; - +interface userAccountInfo { + address: string; + publicKey: string +} export interface UseAuthProps { balanceSetting?: BalanceSetting; /** User will be prompted for authentication on start-up */ authenticateOnMount?: boolean; + userAccountInfo?: userAccountInfo | null } -export const useAuth = ({ balanceSetting, authenticateOnMount = true }: UseAuthProps) => { +export const useAuth = ({ balanceSetting, authenticateOnMount = true, userAccountInfo = null }: UseAuthProps) => { const address = useAuthStore((s) => s.address); const publicKey = useAuthStore((s) => s.publicKey); const name = useAuthStore((s) => s.name); @@ -45,12 +49,12 @@ const setBalance = useAuthStore((s) => s.setBalance); const balanceSetIntervalRef = useRef>(null); - const authenticateUser = useCallback(async () => { + const authenticateUser = useCallback(async (userAccountInfo?: userAccountInfo) => { try { setErrorLoadingUser(null); setIsLoadingUser(true); - const account = await qortalRequest({ + const account = userAccountInfo || await qortalRequest({ action: "GET_USER_ACCOUNT", }); @@ -104,7 +108,10 @@ const setBalance = useAuthStore((s) => s.setBalance); if (authenticateOnMount) { authenticateUser(); } - }, [authenticateOnMount, authenticateUser]); + if(userAccountInfo?.address && userAccountInfo?.publicKey){ + authenticateUser(userAccountInfo); + } + }, [authenticateOnMount, authenticateUser, userAccountInfo?.address, userAccountInfo?.publicKey]); useEffect(() => { if (address && (balanceSetting?.onlyOnMount || (balanceSetting?.interval && !isNaN(balanceSetting?.interval)))) {