()
| 14 | }); |
| 15 | |
| 16 | function 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(); |
nothing calls this directly
no test coverage detected