From c798112b77c5064eab2e007d6c3398d460f6be6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20=C4=86wirko?= Date: Sat, 28 Oct 2023 20:53:22 +0200 Subject: [PATCH] fix NativeAuth configuration --- CHANGELOG.md | 3 +++ package.json | 2 +- src/hooks/common-helpers/getLoginToken.ts | 10 +--------- src/hooks/common-helpers/useDappProvidersSync.tsx | 10 +++------- src/utils/getNativeAuthClient.ts | 8 +++++++- 5 files changed, 15 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e85217..a54bf9c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +### [0.10.2](https://github.com/useElven/core/releases/tag/v0.10.2) (2023-10-28) +- fix NativeAuth configuration + ### [0.10.1](https://github.com/useElven/core/releases/tag/v0.10.1) (2023-10-28) - fix xAlias related types diff --git a/package.json b/package.json index be7b267..9e09e14 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@useelven/core", - "version": "0.10.1", + "version": "0.10.2", "description": "Core React hooks for MultiversX DApps", "license": "MIT", "author": "Julian Ćwirko ", diff --git a/src/hooks/common-helpers/getLoginToken.ts b/src/hooks/common-helpers/getLoginToken.ts index 07539e7..da6fa8f 100644 --- a/src/hooks/common-helpers/getLoginToken.ts +++ b/src/hooks/common-helpers/getLoginToken.ts @@ -5,7 +5,6 @@ import { setLoggingInState, } from '../../store/auth'; import { errorParse } from '../../utils/errorParse'; -import { configState } from '../../store/config'; export const getLoginToken = async () => { const client = getNativeAuthClient(); @@ -14,14 +13,7 @@ export const getLoginToken = async () => { if (!token) { try { setLoggingInState('pending', true); - token = await client.initialize({ - apiUrl: configState?.apiAddress || '', - origin: - typeof window !== 'undefined' && - typeof window.location !== 'undefined' - ? window.location.origin - : '', - }); + token = await client.initialize(); } catch (e) { setLoggingInState('error', errorParse(e)); } finally { diff --git a/src/hooks/common-helpers/useDappProvidersSync.tsx b/src/hooks/common-helpers/useDappProvidersSync.tsx index a63416e..d44fd9a 100644 --- a/src/hooks/common-helpers/useDappProvidersSync.tsx +++ b/src/hooks/common-helpers/useDappProvidersSync.tsx @@ -27,7 +27,7 @@ import { useLogout } from '../useLogout'; import { useConfig } from '../useConfig'; import { useAccount } from '../useAccount'; import { useLoginInfo } from '../useLoginInfo'; -import { NativeAuthClient } from '@multiversx/sdk-native-auth-client'; +import { getNativeAuthClient } from 'src/utils/getNativeAuthClient'; export const useDappProvidersSync = ( accountDone: boolean, @@ -158,9 +158,7 @@ export const useDappProvidersSync = ( } if (signature && address && loginToken) { - const nativeAuthClient = new NativeAuthClient({ - apiUrl: configStateSnap.apiAddress, - }); + const nativeAuthClient = getNativeAuthClient(); const accessToken = nativeAuthClient.getToken( address, loginToken, @@ -190,9 +188,7 @@ export const useDappProvidersSync = ( } if (signature && address && loginToken) { - const nativeAuthClient = new NativeAuthClient({ - apiUrl: configStateSnap.apiAddress, - }); + const nativeAuthClient = getNativeAuthClient(); const accessToken = nativeAuthClient.getToken( address, loginToken, diff --git a/src/utils/getNativeAuthClient.ts b/src/utils/getNativeAuthClient.ts index ec18b37..1ca34f2 100644 --- a/src/utils/getNativeAuthClient.ts +++ b/src/utils/getNativeAuthClient.ts @@ -2,4 +2,10 @@ import { NativeAuthClient } from '@multiversx/sdk-native-auth-client'; import { configState } from '../store/config'; export const getNativeAuthClient = () => - new NativeAuthClient({ apiUrl: configState.apiAddress }); + new NativeAuthClient({ + apiUrl: configState?.apiAddress || '', + origin: + typeof window !== 'undefined' && typeof window.location !== 'undefined' + ? window.location.origin + : '', + });