Skip to content

Commit

Permalink
fix NativeAuth configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
juliancwirko committed Oct 28, 2023
1 parent 18acc72 commit c798112
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 18 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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 <julian.io>",
Expand Down
10 changes: 1 addition & 9 deletions src/hooks/common-helpers/getLoginToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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 {
Expand Down
10 changes: 3 additions & 7 deletions src/hooks/common-helpers/useDappProvidersSync.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 7 additions & 1 deletion src/utils/getNativeAuthClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
: '',
});

0 comments on commit c798112

Please sign in to comment.