Last active
January 30, 2021 17:01
-
-
Save aditya-vijaykumar/b2cefd0cc9797fe8e5731ac891b28f0a to your computer and use it in GitHub Desktop.
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 { | |
ThreeIdConnect, | |
EthereumAuthProvider, | |
} from "3id-connect"; | |
import Ceramic from "@ceramicnetwork/http-client"; | |
import { IDX } from "@ceramicstudio/idx"; | |
import web3Modal from "../utils/provider.js"; | |
//const THREEID_CONNECT_URL = "http://localhost:30001"; | |
//const PRIV_API_URL = "https://ceramic.asclepius.xyz/"; | |
const DEFAULT_API_URL = "http://localhost:7007"; | |
const threeIdConnect = new ThreeIdConnect(); | |
const ceramic = new Ceramic(DEFAULT_API_URL); | |
async ceramicAuth() { | |
const ethProvider = await web3Modal.connect(); | |
const addresses = await ethProvider.request({ method: "eth_accounts" }); | |
console.log("Got the ethaddress"); | |
const authProvider = new EthereumAuthProvider(ethProvider, addresses[0]); | |
await threeIdConnect.connect(authProvider); | |
console.log("3id connect func executed"); | |
const provider = await threeIdConnect.getDidProvider(); | |
console.log("didProvider accessed"); | |
await ceramic.setDIDProvider(provider); | |
console.log("Ceramic DID Provider set"); | |
const idx = new IDX({ceramic}); | |
console.log("new idx instance created"); | |
if (idx.authenticated) { | |
console.log("authenticated IDX!!"); | |
//redirect upon this | |
let auth = true; | |
if (auth) { | |
const profile = await idx.get("profile", idx.id); | |
console.log("My Profile"); | |
console.dir(profile); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment