MCPcopy Create free account
hub / github.com/Web3Auth/Auth / App

Function App

examples/react-example/src/App.tsx:16–127  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

14});
15
16function App() {
17 const [loading, setLoading] = useState(false);
18
19 const printToConsole = (...args: unknown[]): void => {
20 const el = document.querySelector("#console>p");
21 if (el) {
22 el.innerHTML = JSON.stringify(args || {}, null, 2);
23 }
24 };
25
26 const printUserInfo = async () => {
27 const userInfo = auth.getUserInfo();
28 printToConsole(userInfo);
29 };
30
31 async function login() {
32 setLoading(true);
33 try {
34 await auth.login({
35 authConnection: AUTH_CONNECTION.GITHUB,
36 });
37 if (auth.privKey) {
38 await printUserInfo();
39 }
40 setLoading(false);
41 } catch (error) {
42 log.error("error", error);
43 setLoading(false);
44 }
45 }
46
47 useEffect(() => {
48 setLoading(true);
49 async function initializeAuth() {
50 try {
51 await auth.init();
52 if (auth.privKey) {
53 await printUserInfo();
54 }
55 } catch (error) {
56 log.error("error while initialization", error);
57 } finally {
58 setLoading(false);
59 }
60 }
61 initializeAuth();
62 }, []);
63
64 const getEd25519Key = async () => {
65 const { sk } = getED25519Key(auth.privKey);
66 const base58Key = bs58.encode(new Uint8Array(sk));
67 printToConsole(base58Key);
68 };
69
70 const logout = async () => {
71 try {
72 setLoading(true);
73 await auth.logout();

Callers

nothing calls this directly

Calls 2

initializeAuthFunction · 0.85
logoutFunction · 0.85

Tested by

no test coverage detected