UNPKG

ui-for-firebase-authentication

Version:

UI for Firebase Authentication (Firebase UI alternative supporting v9+)

51 lines (50 loc) 2.2 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()); }); }; const codeMap = { //User errors "auth/user-not-found": "No user found with selected email", "auth/email-already-in-use": "An account already exists with this email", "auth/wrong-password": "Incorrect Password", "auth/weak-password": "Password too weak - must be at least 6 characters", "auth/popup-closed-by-user": "Oopsies! Looks like you closed the sign in popup!", //Service Problems "auth/too-many-requests": "Too many recent requests. You can reset your password or try again later", "auth/requires-recent-login": "You must sign in again before you can perform this action", //Configuration issues "auth/unauthorized-domain": "Configuration Error: Unauthorized Domain", }; function getFirebaseResultOrErrorMessage(prom) { return __awaiter(this, void 0, void 0, function* () { try { return yield prom; } catch (e) { if (codeMap[e.code]) { return codeMap[e.code]; } else { return `Unknown Error ${e.message}`; } } }); } function handleFirebasePromise(prom) { return __awaiter(this, void 0, void 0, function* () { //This function should be phased out and removed. let res = yield getFirebaseResultOrErrorMessage(prom); if (typeof res === "string") { alert(res); } else { return res; } }); } export { handleFirebasePromise, getFirebaseResultOrErrorMessage };