This repository was archived by the owner on Dec 25, 2023. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathApp.tsx
More file actions
59 lines (54 loc) · 1.96 KB
/
Copy pathApp.tsx
File metadata and controls
59 lines (54 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { StatusBar } from "expo-status-bar";
import { useState } from "react";
import { StyleSheet, Text, View, Button } from "react-native";
import Web3Auth, { LOGIN_PROVIDER, OPENLOGIN_NETWORK, State } from "@web3auth/react-native-sdk";
import Constants, { AppOwnership } from "expo-constants";
import * as Linking from "expo-linking";
import * as WebBrowser from "expo-web-browser";
import { Buffer } from "buffer";
global.Buffer = global.Buffer || Buffer;
const scheme = "web3authexposample";
const resolvedRedirectUrl =
Constants.appOwnership == AppOwnership.Expo || Constants.appOwnership == AppOwnership.Guest
? Linking.createURL("web3auth", {})
: Linking.createURL("web3auth", { scheme: scheme });
export default function App() {
const [key, setKey] = useState("");
const [errorMsg, setErrorMsg] = useState("");
const [userInfo, setUserInfo] = useState<State>(null);
const login = async () => {
try {
const web3auth = new Web3Auth(WebBrowser, {
clientId: "BA0mVyeHATikwuXVhXWCNjAxHthlw0w84mUhLuxlC4KZKjvmBsbdbmEWTizJ26YzrbKSWbOZbtGYdVDm0ESuYSg",
network: OPENLOGIN_NETWORK.TESTNET,
});
const state = await web3auth.login({
loginProvider: LOGIN_PROVIDER.GOOGLE,
redirectUrl: resolvedRedirectUrl,
});
setKey(state.privKey || "no key");
setUserInfo(state);
} catch (e) {
console.error(e);
setErrorMsg(String(e));
}
};
return (
<View style={styles.container}>
{key !== "" ? <Text>Key: {key}</Text> : null}
{userInfo !== null ? <Text>UserInfo: {JSON.stringify(userInfo)}</Text> : null}
{errorMsg !== "" ? <Text>Error: {errorMsg}</Text> : null}
<Text>Linking URL: {resolvedRedirectUrl}</Text>
<Button title="Login with Web3Auth" onPress={login} />
<StatusBar style="auto" />
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#fff",
alignItems: "center",
justifyContent: "center",
},
});