Skip to content

Commit

Permalink
fix native auth with browser extension
Browse files Browse the repository at this point in the history
  • Loading branch information
juliancwirko committed May 29, 2023
1 parent bb15eb4 commit cbffb8b
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 7 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/juliancwirko/elven.js/releases/tag/v0.10.2) (2023-05-29)
- fix native auth when signing using browser extension

### [0.10.1](https://github.com/juliancwirko/elven.js/releases/tag/v0.10.1) (2023-05-23)
- fix native auth when used with web wallet provider

Expand Down
2 changes: 1 addition & 1 deletion build/elven.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/types/auth/login-with-extension.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import { NativeAuthClient } from '@multiversx/sdk-native-auth-client/lib/src/native.auth.client';
export declare const loginWithExtension: (elven: any, loginToken: string, nativeAuthClient: NativeAuthClient) => Promise<import("@multiversx/sdk-extension-provider/out/extensionProvider").ExtensionProvider | undefined>;
export declare const loginWithExtension: (elven: any, loginToken: string, nativeAuthClient: NativeAuthClient, callbackRoute?: string) => Promise<import("@multiversx/sdk-extension-provider/out/extensionProvider").ExtensionProvider | undefined>;
2 changes: 1 addition & 1 deletion example/elven.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "elven.js",
"version": "0.10.1",
"version": "0.10.2",
"description": "Authenticate, sign and send transactions on the MultiversX blockchain in the browser.",
"type": "module",
"module": "build/elven.js",
Expand Down
13 changes: 11 additions & 2 deletions src/auth/login-with-extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,21 @@ import { NativeAuthClient } from '@multiversx/sdk-native-auth-client/lib/src/nat
export const loginWithExtension = async (
elven: any,
loginToken: string,
nativeAuthClient: NativeAuthClient
nativeAuthClient: NativeAuthClient,
callbackRoute = '/'
) => {
const dappProvider = await initExtensionProvider();

const callbackUrl: string = encodeURIComponent(
`${window.location.origin}${callbackRoute}`
);
const providerLoginData = {
callbackUrl,
token: loginToken,
};

try {
if (dappProvider) await dappProvider.login();
if (dappProvider) await dappProvider.login(providerLoginData);
EventsStore.run(EventStoreEvents.onLoginPending);
} catch (e) {
const err = errorParse(e);
Expand Down
3 changes: 2 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ export class ElvenJS {
const dappProvider = await loginWithExtension(
this,
loginToken,
nativeAuthClient
nativeAuthClient,
options?.callbackRoute
);
this.dappProvider = dappProvider;
}
Expand Down

0 comments on commit cbffb8b

Please sign in to comment.