UNPKG

@salad-labs/loopz-typescript

Version:
43 lines 1.95 kB
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; import { useLogin, usePrivy } from "@privy-io/react-auth"; import { Auth } from "../../auth"; import { useEffect, useRef } from "react"; import { useFundWallet } from "@privy-io/react-auth"; export const usePrivyLogin = () => { const auth = Auth.getInstance(); const initialized = useRef(false); const { ready, authenticated, getAccessToken } = usePrivy(); const disableLogin = !ready || (ready && authenticated); useFundWallet({ onUserExited: (fundInfo) => { var _a; (_a = auth.getCurrentAccount()) === null || _a === void 0 ? void 0 : _a._emit("onFundExit", fundInfo); }, }); useLogin({ onComplete: (_a) => __awaiter(void 0, [_a], void 0, function* ({ user, isNewUser, wasAlreadyAuthenticated, loginMethod, loginAccount, }) { }), onError: (error) => { Auth._emit("__onLoginError", error); }, }); useEffect(() => { if (!initialized.current && ready && !disableLogin) { initialized.current = true; } if (authenticated && ready) { } else if (!authenticated && ready) { } else if (!ready) { } }, [ready, disableLogin, authenticated]); }; //# sourceMappingURL=usePrivyLogin.js.map