Skip to content

Commit

Permalink
Merge pull request #75 from Web3Auth/fix-android-demo-rn-bare
Browse files Browse the repository at this point in the history
Fix Android redirectUrl issue in RN bare
  • Loading branch information
arch1995 authored Jul 7, 2023
2 parents a73c1ac + 17cef96 commit 5bfc340
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 257 deletions.
17 changes: 13 additions & 4 deletions demo/rn-bare-example/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
Button,
ScrollView,
Dimensions,
TextInput,
} from 'react-native';
import * as WebBrowser from '@toruslabs/react-native-web-browser';
import EncryptedStorage from 'react-native-encrypted-storage';
Expand All @@ -17,7 +18,7 @@ import Web3Auth, {
} from '@web3auth/react-native-sdk';
import RPC from './ethersRPC'; // for using ethers.js

const scheme = 'web3authrnbareaggregateexample'; // Or your desired app redirection scheme
const scheme = 'web3authrnbareexample'; // Or your desired app redirection scheme
const resolvedRedirectUrl = `${scheme}://openlogin`;
const clientId =
'BHr_dKcxC0ecKn_2dZQmQeNdjPgWykMkcodEHkVvPMo71qzOV6SgtoN8KCvFdLN7bf34JOm89vWQMLFmSfIo84A';
Expand All @@ -27,6 +28,7 @@ export default function App() {
const [key, setKey] = useState<string | undefined>('');
const [console, setConsole] = useState<string>('');
const [web3auth, setWeb3Auth] = useState<IWeb3Auth | null>(null);
const [email, setEmail] = React.useState('[email protected]');

const login = async () => {
try {
Expand All @@ -42,7 +44,7 @@ export default function App() {
mfaLevel: 'default',
curve: 'secp256k1',
extraLoginOptions: {
login_hint: '[email protected]',
login_hint: email,
connection: 'email',
},
});
Expand All @@ -52,7 +54,7 @@ export default function App() {
setKey(web3auth.privKey);
uiConsole('Logged In');
}
} catch (e) {
} catch (e: any) {
setConsole(e.message);
}
};
Expand Down Expand Up @@ -136,7 +138,7 @@ export default function App() {
uiConsole(message);
};

const uiConsole = (...args) => {
const uiConsole = (...args: unknown[]) => {
setConsole(JSON.stringify(args || {}, null, 2) + '\n\n\n\n' + console);
};

Expand All @@ -155,6 +157,13 @@ export default function App() {

const unloggedInView = (
<View style={styles.buttonArea}>
<TextInput
editable
onChangeText={text => setEmail(text)}
value={email}
// eslint-disable-next-line react-native/no-inline-styles
style={{padding: 10}}
/>
<Button title="Login with Web3Auth" onPress={login} />
</View>
);
Expand Down
6 changes: 6 additions & 0 deletions demo/rn-bare-example/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="web3authrnbareexample" />
</intent-filter>
</activity>
</application>
</manifest>
Loading

0 comments on commit 5bfc340

Please sign in to comment.