Created
May 5, 2021 04:08
-
-
Save phuctm97/8695be1abd32ca1387a0f0bd31a72377 to your computer and use it in GitHub Desktop.
Integrate Torus CustomAuth with Firebase (React)
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