@trap_stevo/legendarybuilderproreact-ui
Version:
The legendary UI & utility API that makes your application a legendary application. ~ Created by Steven Compton
110 lines • 3.91 kB
JavaScript
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import { initializeApp } from "firebase/app";
import { getFirestore } from "firebase/firestore";
import { getDatabase } from "firebase/database";
import { getStorage } from "firebase/storage";
import { getAuth, signInWithEmailAndPassword, signOut as _signOut, sendPasswordResetEmail as _sendPasswordResetEmail, createUserWithEmailAndPassword } from "firebase/auth";
import { GoogleAuthProvider, OAuthProvider, FacebookAuthProvider, GithubAuthProvider, signInWithPopup } from "firebase/auth";
var HUDFirebaseManager = /*#__PURE__*/function () {
function HUDFirebaseManager() {
_classCallCheck(this, HUDFirebaseManager);
this.initializedApps = {};
this.services = {};
}
_createClass(HUDFirebaseManager, [{
key: "initializeHUDFirebaseApp",
value: function initializeHUDFirebaseApp(config) {
var appName = config.projectId;
if (this.initializedApps[appName]) {
return this.initializedApps[appName];
}
var app = initializeApp(config, appName);
this.initializedApps[appName] = app;
return app;
}
}, {
key: "setUpHUDFirebaseServices",
value: function setUpHUDFirebaseServices(app, options) {
if (options.firestore) {
this.services.firestore = options.firestore.reduce(function (account, config) {
account[config.label] = getFirestore(app, config.settings);
return account;
}, {});
}
if (options.database) {
this.services.database = options.database.reduce(function (account, config) {
account[config.label] = getDatabase(app, config.settings);
return account;
}, {});
}
if (options.storage) {
this.services.storage = options.storage.reduce(function (account, config) {
account[config.label] = getStorage(app, config.settings);
return account;
}, {});
}
if (options.auth) {
this.services.auth = getAuth(app);
}
return this.services;
}
}, {
key: "getHUDFirebaseApp",
value: function getHUDFirebaseApp(appName) {
return this.initializedApps[appName] || null;
}
}, {
key: "sendPasswordResetEmail",
value: function sendPasswordResetEmail(email) {
return _sendPasswordResetEmail(this.services.auth, email);
}
}, {
key: "createUser",
value: function createUser(email, password) {
return createUserWithEmailAndPassword(this.services.auth, email, password);
}
}, {
key: "signInWithProvider",
value: function signInWithProvider(providerId) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var provider;
switch (providerId) {
case "google":
provider = new GoogleAuthProvider();
break;
case "apple":
provider = new OAuthProvider("apple.com");
break;
case "facebook":
provider = new FacebookAuthProvider();
break;
case "github":
provider = new GithubAuthProvider();
break;
default:
throw new Error("Unsupported provider ~ ".concat(providerId));
}
if (options.scopes && Array.isArray(options.scopes)) {
options.scopes.forEach(function (scope) {
return provider.addScope(scope);
});
}
return signInWithPopup(this.services.auth, provider);
}
}, {
key: "signIn",
value: function signIn(email, password) {
return signInWithEmailAndPassword(this.services.auth, email, password);
}
}, {
key: "signOut",
value: function signOut() {
return _signOut(this.services.auth);
}
}]);
return HUDFirebaseManager;
}();
;
var hudFirebaseManager = new HUDFirebaseManager();
export { hudFirebaseManager };