UNPKG

mockbase

Version:
156 lines 6.12 kB
"use strict"; 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()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.User = exports.UserInfo = void 0; const user_credential_1 = require("./user-credential"); class UserInfo { constructor(uid, providerId, rest) { var _a, _b, _c, _d; this.uid = uid; this.providerId = providerId; this.displayName = (_a = rest.displayName) !== null && _a !== void 0 ? _a : null; this.email = (_b = rest.email) !== null && _b !== void 0 ? _b : null; this.phoneNumber = (_c = rest.phoneNumber) !== null && _c !== void 0 ? _c : null; this.photoURL = (_d = rest.photoURL) !== null && _d !== void 0 ? _d : null; } } exports.UserInfo = UserInfo; class User { constructor(data, store) { this.store = store; Object.assign(this, data, { displayName: data.displayName || null, email: data.email || null, emailVerified: data.emailVerified || false, metadata: { creationTime: (data.metadata && data.metadata.creationTime) || new Date().toISOString(), lastSignInTime: data.metadata && data.metadata.lastSignInTime, }, phoneNumber: data.phoneNumber || null, photoURL: data.photoURL || null, providerData: data.providerData || [], refreshToken: "", tenantId: data.tenantId || null, }); } delete() { throw new Error("Method not implemented."); } getIdToken(forceRefresh) { throw new Error("Method not implemented."); } getIdTokenResult(forceRefresh) { throw new Error("Method not implemented."); } getToken(forceRefresh) { throw new Error("Method not implemented."); } linkAndRetrieveDataWithCredential(credential) { throw new Error("Method not implemented."); } linkWithCredential(credential) { throw new Error("Method not implemented."); } linkWithPhoneNumber(phoneNumber, applicationVerifier) { throw new Error("Method not implemented."); } linkWithSocial(provider) { return __awaiter(this, void 0, void 0, function* () { if (this.providerData.some((info) => info.providerId === provider.providerId)) { throw new Error("auth/provider-already-linked"); } const data = yield this.store.consumeSocialMock(provider); this.providerData = [...this.providerData, new UserInfo(this.uid, provider.providerId, data)]; this.store.update(this.uid, { providerData: this.providerData, }); this.providerId = provider.providerId; return new user_credential_1.UserCredential(this, "link", { isNewUser: false }); }); } linkWithPopup(provider) { return this.linkWithSocial(provider); } linkWithRedirect(provider) { return __awaiter(this, void 0, void 0, function* () { throw new Error("Method not implemented."); }); } reauthenticateAndRetrieveDataWithCredential(credential) { throw new Error("Method not implemented."); } reauthenticateWithCredential(credential) { throw new Error("Method not implemented."); } reauthenticateWithPhoneNumber(phoneNumber, applicationVerifier) { throw new Error("Method not implemented."); } reauthenticateWithPopup(provider) { throw new Error("Method not implemented."); } reauthenticateWithRedirect(provider) { throw new Error("Method not implemented."); } reload() { return Promise.resolve(); } sendEmailVerification(actionCodeSettings) { throw new Error("Method not implemented."); } toJSON() { const self = this; return Object.assign({}, self); } unlink(providerId) { return __awaiter(this, void 0, void 0, function* () { const index = this.providerData.findIndex((info) => info.providerId === providerId); if (index === -1) { throw new Error("auth/no-such-provider"); } this.providerData.splice(index, 1); this.store.update(this.uid, { providerData: this.providerData, }); return this; }); } updateEmail(newEmail) { if (this.email === newEmail) { return Promise.resolve(); } const anotherUser = this.store.findByEmail(newEmail); if (anotherUser) { return Promise.reject(new Error("auth/email-already-in-use")); } this.email = newEmail; this.store.update(this.uid, { email: newEmail }); return Promise.resolve(); } updatePassword(newPassword) { this.password = newPassword; this.store.update(this.uid, { password: newPassword }); return Promise.resolve(); } updatePhoneNumber(phoneCredential) { throw new Error("Method not implemented."); } updateProfile({ displayName, photoURL, }) { this.displayName = displayName || null; this.photoURL = photoURL || null; this.store.update(this.uid, { displayName, photoURL }); return Promise.resolve(); } verifyBeforeUpdateEmail(newEmail, actionCodeSettings) { throw new Error("Method not implemented."); } } exports.User = User; //# sourceMappingURL=user.js.map