Skip to content

Instantly share code, notes, and snippets.

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