export {}; // // import React from 'react'; // // import logo from './logo.svg'; // import '../App.css'; // import { getAuth, RecaptchaVerifier, signInWithEmailAndPassword, signInWithPhoneNumber, ConfirmationResult, UserCredential, signOut } from "firebase/auth"; // import { initializeApp } from "firebase/app"; // import { useAuthState } from 'react-firebase-hooks/auth'; // import { Card, Col, Row } from "antd"; // import { Api, UserReadPrivateResponse, ErrorResponse } from "@newstackdev/iosdk-newgraph-client-js"; // import { useEffect, useState } from 'react'; // import { useHistory } from 'react-router-dom'; // const baseUrl = "https://api-eu-sit.newlife.io/creator"; // // TODO: Add SDKs for Firebase products that you want to use // // https://firebase.google.com/docs/web/setup#available-libraries // // Your web app's Firebase configuration // // For Firebase JS SDK v7.20.0 and later, measurementId is optional // const firebaseConfig = { // apiKey: "AIzaSyD-OLxk7rwlY3qqsHlFff7fYFQ2xmW78ZM", // authDomain: "newlifeio.firebaseapp.com", // projectId: "newlifeio", // storageBucket: "newlifeio.appspot.com", // messagingSenderId: "360722214510", // appId: "1:360722214510:web:d088a1e106fef50262007f", // measurementId: "G-PJWYRPZSNM" // }; // // Initialize Firebase // initializeApp(firebaseConfig); // const auth = getAuth(); // const initRecaptchaVerifier = () => { // // if((window as any).recaptchaVerifier) // // return; // // (window as any). // return new RecaptchaVerifier('sign-in-button', { // 'size': 'invisible', // 'callback': (response: any) => { // // reCAPTCHA solved, allow signInWithPhoneNumber. // //alert(response); // // signInWithPhoneNumber // // onSignInSubmit() // } // }, auth); // } // let verificationCodePromise: Promise | undefined; // const getVerificationCode = (phoneNumber: string) => { // if (verificationCodePromise) // return; // return verificationCodePromise = signInWithPhoneNumber(auth, phoneNumber, initRecaptchaVerifier()); // } // export const logout = () => { // auth.signOut(); // }; // export class SecureApi extends Api<{ token: string }> { }; // const creatorApi = new SecureApi({ // baseUrl, securityWorker: (securityData: { token: string } | null) => { // return (!securityData ? {} : { headers: { Authorization: securityData.token } }) // } // }); // const updateToken = (token: string) => creatorApi.setSecurityData({ token }); // export class UserInfo { // status: string = ""; // token: string = ""; // user: UserReadPrivateResponse = {} // fbUser?: UserCredential; // loading: boolean = false; // signOut?: () => void; // }; // export function Auth(props: React.PropsWithChildren<{ onApiChanged: (v?: SecureApi, userInfo?: UserInfo) => any }>) { // const [fbUser, loading, error] = useAuthState(auth); // const [currentUserLoading, setCurrentUserLoading] = useState(); // const [currentUser, setCurrentUser] = useState(new UserInfo()); //{ currentUser, }); // const [phoneNumber, setPhoneNumber] = useState("+420111111111"); // // const [phoneVerificationCode, setPhoneVerificationCode] = useState("111111"); // const [verifier, setVerifier] = useState<({ verify: (verificationCode: string) => any }) | undefined>(); // // const [userCredential, setUserCredential] = useState(); // const history = useHistory(); // const clearStateAndSignOut = () => { // signOut(auth); // setPhoneNumber(""); // setPhoneVerificationCode(""); // setVerifier(undefined); // // setUserCredential(undefined); // setCurrentUser({} as any); // props.onApiChanged(undefined, undefined); // } // const loadCurrentUser = (async () => { // if(currentUser || currentUserLoading || !fbUser || !fbUser.accessToken) // return; // // setCurrentUserLoading(true); // try { // const cu = await creatorApi.user.currentList(); // const userInfo = { user: cu.data, fbUser, token: fbUser.accessToken, status: "user", signOut: clearStateAndSignOut }; // setCurrentUser(currentUser); // props.onApiChanged(creatorApi, ); // } catch (_ex) { // const ex: { error: ErrorResponse } = _ex as any; // console.log(ex) // if (ex.error) { // setCurrentUser({ user: {}, ...currentUser, status: "newuser", signOut: clearStateAndSignOut }); // if (ex.error.statusCode === 404) { // const userInfo = { user: {}, fbUser, token: fbUser.accessToken, status: "newuser", signOut: clearStateAndSignOut }; // props.onApiChanged(creatorApi, userInfo); // history.push("/user-create", {}); // return; // } // alert(ex.error.errorMessage); // } // const otherError = _ex as any; // alert(otherError.message); // clearStateAndSignOut(); // } finally { // setCurrentUserLoading(false); // } // }); // useEffect(() => { loadCurrentUser() }, [currentUserLoading]); // useEffect(() => { // if (!currentUser?.fbUser && !loading && !error) { // initRecaptchaVerifier(); // return // } // if (!fbUser || !fbUser.accessToken) // return // updateToken(fbUser.accessToken); // setCurrentUserLoading(false); // }, [currentUser?.fbUser && fbUser && fbUser.accessToken]); // return ( //
// {/* logo */} // { // !fbUser && // <> // setPhoneNumber(e.target.value)} /> // // setPhoneVerificationCode(e.target.value)} /> // // // } // { // userCredential && !currentUser &&

Checking user status...

// } // {/* { // !fbUser && // // } */} // { // fbUser && // // } //
// ); // }