Last active
May 5, 2022 04:01
-
-
Save phuctm97/2777030c460fba4996ce6443d55c39b4 to your computer and use it in GitHub Desktop.
Torus React/Firebase login
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useState } from "react"; | |
import TorusSdk from "@toruslabs/torus-direct-web-sdk"; | |
const App = () => { | |
const [torusSdk, setTorusSdk] = useState(); | |
const onMount = async () => { | |
const sdk = new TorusSdk({ | |
baseUrl: `${window.location.origin}/auth`, | |
enableLogging: true, | |
network: "testnet", // details for test net | |
}); | |
await sdk.init({ skipSw: false }); | |
setTorusSdk(sdk); | |
}; | |
useEffect(() => { | |
onMount(); | |
}, []); | |
const onClickLogin = async () => { | |
if(!torusSdk) return; | |
const user = await login(); | |
const { privateKey, publicAddress } = await torusSdk.getTorusKey("peer-firebase-testnet", user.sub, { verifier_id: user.sub }, user.idToken); | |
}; | |
return <Component onClickLogin={onClickLogin} /> | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment