import firebase from "firebase/app";
import "firebase/auth";
import env from "../env";

import { initializeApp } from "firebase/app";
import { getAuth, initializeAuth , getReactNativePersistence} from "firebase/auth";
import AsyncStorage from "@react-native-async-storage/async-storage";

const defaultApp = initializeApp(env.firebase);
initializeAuth(defaultApp, {
  persistence: getReactNativePersistence(AsyncStorage),
});
export const auth = getAuth();

//export const analytics = firebase.analytics();

export default firebase;

export const getCurrentUser = () => {
  return new Promise((resolve, reject) => {
    const unsubscribe = auth.onAuthStateChanged((userAuth) => {
      unsubscribe();
      resolve(userAuth);
    }, reject);
  });
};
