Skip to content

Commit aca8d6a

Browse files
make redirect url mandatory
1 parent 4f43f92 commit aca8d6a

File tree

5 files changed

+116
-101
lines changed

5 files changed

+116
-101
lines changed

demo/rn-bare-example/App.tsx

Lines changed: 79 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
TextInput,
1010
View,
1111
} from 'react-native';
12-
import React, {useEffect, useState} from 'react';
12+
import {useEffect, useState} from 'react';
1313
import Web3Auth, {
1414
IWeb3Auth,
1515
LOGIN_PROVIDER,
@@ -44,7 +44,7 @@ export default function App() {
4444
const [key, setKey] = useState<string | undefined>('');
4545
const [console, setConsole] = useState<string>('');
4646
const [web3auth, setWeb3Auth] = useState<IWeb3Auth | null>(null);
47-
const [email, setEmail] = React.useState('[email protected]');
47+
const [email, setEmail] = useState('[email protected]');
4848

4949
const login = async () => {
5050
try {
@@ -56,7 +56,6 @@ export default function App() {
5656
setConsole('Logging in');
5757
await web3auth.login({
5858
loginProvider: LOGIN_PROVIDER.EMAIL_PASSWORDLESS,
59-
redirectUrl: resolvedRedirectUrl,
6059
extraLoginOptions: {
6160
login_hint: email,
6261
},
@@ -129,80 +128,85 @@ export default function App() {
129128
// null,
130129
// ];
131130
// const params = ['Hello World', address];
132-
const params = [];
133-
params.push('Hello World');
134-
params.push(address);
131+
// const params = [{ }];
132+
// params.push('Hello World');
133+
// params.push(address);
135134

136-
// const params = [
137-
// '0x0000000000000000000000000000000000000000',
138-
// {
139-
// types: {
140-
// EIP712Domain: [
141-
// {
142-
// name: 'name',
143-
// type: 'string',
144-
// },
145-
// {
146-
// name: 'version',
147-
// type: 'string',
148-
// },
149-
// {
150-
// name: 'chainId',
151-
// type: 'uint256',
152-
// },
153-
// {
154-
// name: 'verifyingContract',
155-
// type: 'address',
156-
// },
157-
// ],
158-
// Person: [
159-
// {
160-
// name: 'name',
161-
// type: 'string',
162-
// },
163-
// {
164-
// name: 'wallet',
165-
// type: 'address',
166-
// },
167-
// ],
168-
// Mail: [
169-
// {
170-
// name: 'from',
171-
// type: 'Person',
172-
// },
173-
// {
174-
// name: 'to',
175-
// type: 'Person',
176-
// },
177-
// {
178-
// name: 'contents',
179-
// type: 'string',
180-
// },
181-
// ],
182-
// },
183-
// primaryType: 'Mail',
184-
// domain: {
185-
// name: 'Ether Mail',
186-
// version: '1',
187-
// chainId: 1,
188-
// verifyingContract: '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC',
189-
// },
190-
// message: {
191-
// from: {
192-
// name: 'Cow',
193-
// wallet: address,
194-
// },
195-
// to: {
196-
// name: 'Bob',
197-
// wallet: '0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB',
198-
// },
199-
// contents: 'Hello, Bob!',
200-
// },
201-
// },
202-
// ];
135+
const params = [
136+
address,
137+
{
138+
types: {
139+
EIP712Domain: [
140+
{
141+
name: 'name',
142+
type: 'string',
143+
},
144+
{
145+
name: 'version',
146+
type: 'string',
147+
},
148+
{
149+
name: 'chainId',
150+
type: 'uint256',
151+
},
152+
{
153+
name: 'verifyingContract',
154+
type: 'address',
155+
},
156+
],
157+
Person: [
158+
{
159+
name: 'name',
160+
type: 'string',
161+
},
162+
{
163+
name: 'wallet',
164+
type: 'address',
165+
},
166+
],
167+
Mail: [
168+
{
169+
name: 'from',
170+
type: 'Person',
171+
},
172+
{
173+
name: 'to',
174+
type: 'Person',
175+
},
176+
{
177+
name: 'contents',
178+
type: 'string',
179+
},
180+
],
181+
},
182+
primaryType: 'Mail',
183+
domain: {
184+
name: 'Ether Mail',
185+
version: '1',
186+
chainId: 1,
187+
verifyingContract: '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC',
188+
},
189+
message: {
190+
from: {
191+
name: 'Cow',
192+
wallet: address,
193+
},
194+
to: {
195+
name: 'Bob',
196+
wallet: '0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB',
197+
},
198+
contents: 'Hello, Bob!',
199+
},
200+
},
201+
];
203202

204203
setConsole('Request Signature');
205-
await web3auth.request(chainConfig, 'personal_sign', params);
204+
const res = await web3auth.request(
205+
chainConfig,
206+
'eth_signTypedData_v4',
207+
params,
208+
);
209+
uiConsole(res);
206210
};
207211

208212
useEffect(() => {
@@ -214,6 +218,7 @@ export default function App() {
214218
loginConfig: {},
215219
enableLogging: true,
216220
buildEnv: 'testing',
221+
redirectUrl: resolvedRedirectUrl,
217222
});
218223
setWeb3Auth(auth);
219224
await auth.init();
Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,31 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
22

3-
<uses-permission android:name="android.permission.INTERNET" />
3+
<uses-permission android:name="android.permission.INTERNET" />
44

5-
<application
6-
android:name=".MainApplication"
5+
<application
6+
android:name=".MainApplication"
7+
android:label="@string/app_name"
8+
android:icon="@mipmap/ic_launcher"
9+
android:roundIcon="@mipmap/ic_launcher_round"
10+
android:allowBackup="false"
11+
android:theme="@style/AppTheme">
12+
<activity
13+
android:name=".MainActivity"
714
android:label="@string/app_name"
8-
android:icon="@mipmap/ic_launcher"
9-
android:roundIcon="@mipmap/ic_launcher_round"
10-
android:allowBackup="false"
11-
android:theme="@style/AppTheme">
12-
<activity
13-
android:name=".MainActivity"
14-
android:label="@string/app_name"
15-
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode"
16-
android:launchMode="singleTask"
17-
android:windowSoftInputMode="adjustResize"
18-
android:exported="true">
19-
<intent-filter>
20-
<action android:name="android.intent.action.MAIN" />
21-
<category android:name="android.intent.category.LAUNCHER" />
22-
</intent-filter>
23-
</activity>
24-
</application>
25-
</manifest>
15+
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode"
16+
android:launchMode="singleTask"
17+
android:windowSoftInputMode="adjustResize"
18+
android:exported="true">
19+
<intent-filter>
20+
<action android:name="android.intent.action.MAIN" />
21+
<category android:name="android.intent.category.LAUNCHER" />
22+
</intent-filter>
23+
<intent-filter>
24+
<action android:name="android.intent.action.VIEW" />
25+
<category android:name="android.intent.category.DEFAULT" />
26+
<category android:name="android.intent.category.BROWSABLE" />
27+
<data android:scheme="web3authrnbareexample" />
28+
</intent-filter>
29+
</activity>
30+
</application>
31+
</manifest>

demo/rn-bare-example/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Web3Auth.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ class Web3Auth implements IWeb3Auth {
292292
hash: { b64Params: jsonToBase64(configParams) },
293293
});
294294

295-
this.webBrowser.openAuthSessionAsync(loginUrl, dataObject.params.redirectUrl);
295+
this.webBrowser.openAuthSessionAsync(loginUrl, this.options.redirectUrl);
296296
}
297297

298298
async request(chainConfig: ChainConfig, method: string, params: unknown[], path: string = "wallet/request"): Promise<string> {
@@ -326,16 +326,19 @@ class Web3Auth implements IWeb3Auth {
326326
baseURL: url,
327327
hash: { b64Params: jsonToBase64(configParams) },
328328
});
329+
// eslint-disable-next-line no-console
330+
console.log(loginUrl);
329331

330-
const result = await this.webBrowser.openAuthSessionAsync(loginUrl, dataObject.params.redirectUrl);
331-
332+
const result = await this.webBrowser.openAuthSessionAsync(loginUrl, this.options.redirectUrl);
333+
// eslint-disable-next-line no-console
334+
console.log(result, "result");
332335
if (result.type !== "success" || !result.url) {
333336
log.error(`[Web3Auth] login flow failed with error type ${result.type}`);
334337
throw LoginError.loginFailed(`login flow failed with error type ${result.type}`);
335338
}
336339

337340
const { success, result: requestResult, error } = getHashQueryParams(result.url);
338-
if (error || success === "false") {
341+
if (error || success === "false" || !success) {
339342
throw RequestError.fromCode(5000, error);
340343
}
341344
return requestResult;

src/types/interface.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ type SdkSpecificInitParams = {
1818
walletSdkURL?: string;
1919
};
2020

21-
export type SdkInitParams = Omit<OpenLoginOptions & SdkSpecificInitParams, "uxMode" | "replaceUrlOnRedirect" | "storageKey">;
21+
export type SdkInitParams = Omit<OpenLoginOptions & SdkSpecificInitParams, "uxMode" | "replaceUrlOnRedirect" | "storageKey"> &
22+
Pick<OpenLoginOptions, "redirectUrl">;
2223

2324
export type SdkLoginParams = Omit<LoginParams, "getWalletKey">;
2425

0 commit comments

Comments
 (0)