UNPKG

@stanfordspezi/spezi-web-design-system

Version:

Stanford Biodesign Digital Health Spezi Web Design System

1,412 lines 73.7 kB
import { L as Pe, g as Ce, i as be, a as Re, _ as Q, C as Z, r as ee, b as Ue, c as H, d as K, e as g, f as A, h as f, j as Oe, k as le, F as de, l as Le, q as he, n as Me } from "./SignInForm-4TsWBtIM.mjs"; import { _ as fe } from "./tslib.es6-xB3F9GiN.mjs"; import { useState as De, useEffect as Fe } from "react"; const kt = (i) => ({ displayName: i.displayName, email: i.email, phoneNumber: i.phoneNumber, photoURL: i.photoURL, providerId: i.providerId, uid: i.uid }), St = (i) => i.displayName || i.email || i.uid; function pe() { return { "dependent-sdk-initialized-before-auth": "Another Firebase SDK was initialized and is trying to use Auth before Auth is initialized. Please be sure to call `initializeAuth` or `getAuth` before starting any other Firebase SDK." }; } const xe = pe, me = new K("auth", "Firebase", pe()); /** * @license * Copyright 2020 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ const P = new Pe("@firebase/auth"); function Ve(i, ...e) { P.logLevel <= le.WARN && P.warn(`Auth (${H}): ${i}`, ...e); } function N(i, ...e) { P.logLevel <= le.ERROR && P.error(`Auth (${H}): ${i}`, ...e); } /** * @license * Copyright 2020 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ function te(i, ...e) { throw $(i, ...e); } function _e(i, ...e) { return $(i, ...e); } function ge(i, e, t) { const r = Object.assign(Object.assign({}, xe()), { [e]: t }); return new K("auth", "Firebase", r).create(e, { appName: i.name }); } function E(i) { return ge(i, "operation-not-supported-in-this-environment", "Operations that alter the current user are not supported in conjunction with FirebaseServerApp"); } function $(i, ...e) { if (typeof i != "string") { const t = e[0], r = [...e.slice(1)]; return r[0] && (r[0].appName = i.name), i._errorFactory.create(t, ...r); } return me.create(i, ...e); } function u(i, e, ...t) { if (!i) throw $(e, ...t); } function T(i) { const e = "INTERNAL ASSERTION FAILED: " + i; throw N(e), new Error(e); } function C(i, e) { i || T(e); } function ze() { return ie() === "http:" || ie() === "https:"; } function ie() { var i; return typeof self < "u" && ((i = self.location) === null || i === void 0 ? void 0 : i.protocol) || null; } /** * @license * Copyright 2020 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ function He() { return typeof navigator < "u" && navigator && "onLine" in navigator && typeof navigator.onLine == "boolean" && // Apply only for traditional web apps and Chrome extensions. // This is especially true for Cordova apps which have unreliable // navigator.onLine behavior unless cordova-plugin-network-information is // installed which overwrites the native navigator.onLine value and // defines navigator.connection. (ze() || Ue() || "connection" in navigator) ? navigator.onLine : !0; } function Ke() { if (typeof navigator > "u") return null; const i = navigator; return ( // Most reliable, but only supported in Chrome/Firefox. i.languages && i.languages[0] || // Supported in most browsers, but returns the language of the browser // UI, not the language set in browser settings. i.language || // Couldn't determine language. null ); } /** * @license * Copyright 2020 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ class k { constructor(e, t) { this.shortDelay = e, this.longDelay = t, C(t > e, "Short delay should be less than long delay!"), this.isMobile = be() || Re(); } get() { return He() ? this.isMobile ? this.longDelay : this.shortDelay : Math.min(5e3, this.shortDelay); } } /** * @license * Copyright 2020 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ function $e(i, e) { C(i.emulator, "Emulator should always be set here"); const { url: t } = i.emulator; return e ? `${t}${e.startsWith("/") ? e.slice(1) : e}` : t; } /** * @license * Copyright 2020 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ class Ie { static initialize(e, t, r) { this.fetchImpl = e, t && (this.headersImpl = t), r && (this.responseImpl = r); } static fetch() { if (this.fetchImpl) return this.fetchImpl; if (typeof self < "u" && "fetch" in self) return self.fetch; if (typeof globalThis < "u" && globalThis.fetch) return globalThis.fetch; if (typeof fetch < "u") return fetch; T("Could not find fetch implementation, make sure you call FetchProvider.initialize() with an appropriate polyfill"); } static headers() { if (this.headersImpl) return this.headersImpl; if (typeof self < "u" && "Headers" in self) return self.Headers; if (typeof globalThis < "u" && globalThis.Headers) return globalThis.Headers; if (typeof Headers < "u") return Headers; T("Could not find Headers implementation, make sure you call FetchProvider.initialize() with an appropriate polyfill"); } static response() { if (this.responseImpl) return this.responseImpl; if (typeof self < "u" && "Response" in self) return self.Response; if (typeof globalThis < "u" && globalThis.Response) return globalThis.Response; if (typeof Response < "u") return Response; T("Could not find Response implementation, make sure you call FetchProvider.initialize() with an appropriate polyfill"); } } /** * @license * Copyright 2020 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ const We = { // Custom token errors. CREDENTIAL_MISMATCH: "custom-token-mismatch", // This can only happen if the SDK sends a bad request. MISSING_CUSTOM_TOKEN: "internal-error", // Create Auth URI errors. INVALID_IDENTIFIER: "invalid-email", // This can only happen if the SDK sends a bad request. MISSING_CONTINUE_URI: "internal-error", // Sign in with email and password errors (some apply to sign up too). INVALID_PASSWORD: "wrong-password", // This can only happen if the SDK sends a bad request. MISSING_PASSWORD: "missing-password", // Thrown if Email Enumeration Protection is enabled in the project and the email or password is // invalid. INVALID_LOGIN_CREDENTIALS: "invalid-credential", // Sign up with email and password errors. EMAIL_EXISTS: "email-already-in-use", PASSWORD_LOGIN_DISABLED: "operation-not-allowed", // Verify assertion for sign in with credential errors: INVALID_IDP_RESPONSE: "invalid-credential", INVALID_PENDING_TOKEN: "invalid-credential", FEDERATED_USER_ID_ALREADY_LINKED: "credential-already-in-use", // This can only happen if the SDK sends a bad request. MISSING_REQ_TYPE: "internal-error", // Send Password reset email errors: EMAIL_NOT_FOUND: "user-not-found", RESET_PASSWORD_EXCEED_LIMIT: "too-many-requests", EXPIRED_OOB_CODE: "expired-action-code", INVALID_OOB_CODE: "invalid-action-code", // This can only happen if the SDK sends a bad request. MISSING_OOB_CODE: "internal-error", // Operations that require ID token in request: CREDENTIAL_TOO_OLD_LOGIN_AGAIN: "requires-recent-login", INVALID_ID_TOKEN: "invalid-user-token", TOKEN_EXPIRED: "user-token-expired", USER_NOT_FOUND: "user-token-expired", // Other errors. TOO_MANY_ATTEMPTS_TRY_LATER: "too-many-requests", PASSWORD_DOES_NOT_MEET_REQUIREMENTS: "password-does-not-meet-requirements", // Phone Auth related errors. INVALID_CODE: "invalid-verification-code", INVALID_SESSION_INFO: "invalid-verification-id", INVALID_TEMPORARY_PROOF: "invalid-credential", MISSING_SESSION_INFO: "missing-verification-id", SESSION_EXPIRED: "code-expired", // Other action code errors when additional settings passed. // MISSING_CONTINUE_URI is getting mapped to INTERNAL_ERROR above. // This is OK as this error will be caught by client side validation. MISSING_ANDROID_PACKAGE_NAME: "missing-android-pkg-name", UNAUTHORIZED_DOMAIN: "unauthorized-continue-uri", // getProjectConfig errors when clientId is passed. INVALID_OAUTH_CLIENT_ID: "invalid-oauth-client-id", // User actions (sign-up or deletion) disabled errors. ADMIN_ONLY_OPERATION: "admin-restricted-operation", // Multi factor related errors. INVALID_MFA_PENDING_CREDENTIAL: "invalid-multi-factor-session", MFA_ENROLLMENT_NOT_FOUND: "multi-factor-info-not-found", MISSING_MFA_ENROLLMENT_ID: "missing-multi-factor-info", MISSING_MFA_PENDING_CREDENTIAL: "missing-multi-factor-session", SECOND_FACTOR_EXISTS: "second-factor-already-in-use", SECOND_FACTOR_LIMIT_EXCEEDED: "maximum-second-factor-count-exceeded", // Blocking functions related errors. BLOCKING_FUNCTION_ERROR_RESPONSE: "internal-error", // Recaptcha related errors. RECAPTCHA_NOT_ENABLED: "recaptcha-not-enabled", MISSING_RECAPTCHA_TOKEN: "missing-recaptcha-token", INVALID_RECAPTCHA_TOKEN: "invalid-recaptcha-token", INVALID_RECAPTCHA_ACTION: "invalid-recaptcha-action", MISSING_CLIENT_TYPE: "missing-client-type", MISSING_RECAPTCHA_VERSION: "missing-recaptcha-version", INVALID_RECAPTCHA_VERSION: "invalid-recaptcha-version", INVALID_REQ_TYPE: "invalid-req-type" /* AuthErrorCode.INVALID_REQ_TYPE */ }; /** * @license * Copyright 2020 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ const Ge = [ "/v1/accounts:signInWithCustomToken", "/v1/accounts:signInWithEmailLink", "/v1/accounts:signInWithIdp", "/v1/accounts:signInWithPassword", "/v1/accounts:signInWithPhoneNumber", "/v1/token" /* Endpoint.TOKEN */ ], je = new k(3e4, 6e4); function ve(i, e) { return i.tenantId && !e.tenantId ? Object.assign(Object.assign({}, e), { tenantId: i.tenantId }) : e; } async function U(i, e, t, r, n = {}) { return ye(i, n, async () => { let s = {}, a = {}; r && (e === "GET" ? a = r : s = { body: JSON.stringify(r) }); const c = he(Object.assign({ key: i.config.apiKey }, a)).slice(1), o = await i._getAdditionalHeaders(); o[ "Content-Type" /* HttpHeader.CONTENT_TYPE */ ] = "application/json", i.languageCode && (o[ "X-Firebase-Locale" /* HttpHeader.X_FIREBASE_LOCALE */ ] = i.languageCode); const l = Object.assign({ method: e, headers: o }, s); return Me() || (l.referrerPolicy = "no-referrer"), Ie.fetch()(await Te(i, i.config.apiHost, t, c), l); }); } async function ye(i, e, t) { i._canInitEmulator = !1; const r = Object.assign(Object.assign({}, We), e); try { const n = new qe(i), s = await Promise.race([ t(), n.promise ]); n.clearNetworkTimeout(); const a = await s.json(); if ("needConfirmation" in a) throw S(i, "account-exists-with-different-credential", a); if (s.ok && !("errorMessage" in a)) return a; { const c = s.ok ? a.errorMessage : a.error.message, [o, l] = c.split(" : "); if (o === "FEDERATED_USER_ID_ALREADY_LINKED") throw S(i, "credential-already-in-use", a); if (o === "EMAIL_EXISTS") throw S(i, "email-already-in-use", a); if (o === "USER_DISABLED") throw S(i, "user-disabled", a); const d = r[o] || o.toLowerCase().replace(/[_\s]+/g, "-"); if (l) throw ge(i, d, l); te(i, d); } } catch (n) { if (n instanceof de) throw n; te(i, "network-request-failed", { message: String(n) }); } } async function Te(i, e, t, r) { const n = `${e}${t}?${r}`, s = i, a = s.config.emulator ? $e(i.config, n) : `${i.config.apiScheme}://${n}`; return Ge.includes(t) && (await s._persistenceManagerAvailable, s._getPersistenceType() === "COOKIE") ? s._getPersistence()._getFinalTarget(a).toString() : a; } class qe { clearNetworkTimeout() { clearTimeout(this.timer); } constructor(e) { this.auth = e, this.timer = null, this.promise = new Promise((t, r) => { this.timer = setTimeout(() => r(_e( this.auth, "network-request-failed" /* AuthErrorCode.NETWORK_REQUEST_FAILED */ )), je.get()); }); } } function S(i, e, t) { const r = { appName: i.name }; t.email && (r.email = t.email), t.phoneNumber && (r.phoneNumber = t.phoneNumber); const n = _e(i, e, r); return n.customData._tokenResponse = t, n; } /** * @license * Copyright 2020 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ async function Je(i, e) { return U(i, "POST", "/v1/accounts:delete", e); } async function b(i, e) { return U(i, "POST", "/v1/accounts:lookup", e); } /** * @license * Copyright 2020 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ function w(i) { if (i) try { const e = new Date(Number(i)); if (!isNaN(e.getTime())) return e.toUTCString(); } catch { } } async function Be(i, e = !1) { const t = A(i), r = await t.getIdToken(e), n = we(r); u( n && n.exp && n.auth_time && n.iat, t.auth, "internal-error" /* AuthErrorCode.INTERNAL_ERROR */ ); const s = typeof n.firebase == "object" ? n.firebase : void 0, a = s == null ? void 0 : s.sign_in_provider; return { claims: n, token: r, authTime: w(F(n.auth_time)), issuedAtTime: w(F(n.iat)), expirationTime: w(F(n.exp)), signInProvider: a || null, signInSecondFactor: (s == null ? void 0 : s.sign_in_second_factor) || null }; } function F(i) { return Number(i) * 1e3; } function we(i) { const [e, t, r] = i.split("."); if (e === void 0 || t === void 0 || r === void 0) return N("JWT malformed, contained fewer than 3 sections"), null; try { const n = Le(t); return n ? JSON.parse(n) : (N("Failed to decode base64 JWT payload"), null); } catch (n) { return N("Caught error parsing JWT payload as JSON", n == null ? void 0 : n.toString()), null; } } function re(i) { const e = we(i); return u( e, "internal-error" /* AuthErrorCode.INTERNAL_ERROR */ ), u( typeof e.exp < "u", "internal-error" /* AuthErrorCode.INTERNAL_ERROR */ ), u( typeof e.iat < "u", "internal-error" /* AuthErrorCode.INTERNAL_ERROR */ ), Number(e.exp) - Number(e.iat); } /** * @license * Copyright 2020 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ async function V(i, e, t = !1) { if (t) return e; try { return await e; } catch (r) { throw r instanceof de && Xe(r) && i.auth.currentUser === i && await i.auth.signOut(), r; } } function Xe({ code: i }) { return i === "auth/user-disabled" || i === "auth/user-token-expired"; } /** * @license * Copyright 2020 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ class Ye { constructor(e) { this.user = e, this.isRunning = !1, this.timerId = null, this.errorBackoff = 3e4; } _start() { this.isRunning || (this.isRunning = !0, this.schedule()); } _stop() { this.isRunning && (this.isRunning = !1, this.timerId !== null && clearTimeout(this.timerId)); } getInterval(e) { var t; if (e) { const r = this.errorBackoff; return this.errorBackoff = Math.min( this.errorBackoff * 2, 96e4 /* Duration.RETRY_BACKOFF_MAX */ ), r; } else { this.errorBackoff = 3e4; const n = ((t = this.user.stsTokenManager.expirationTime) !== null && t !== void 0 ? t : 0) - Date.now() - 3e5; return Math.max(0, n); } } schedule(e = !1) { if (!this.isRunning) return; const t = this.getInterval(e); this.timerId = setTimeout(async () => { await this.iteration(); }, t); } async iteration() { try { await this.user.getIdToken(!0); } catch (e) { (e == null ? void 0 : e.code) === "auth/network-request-failed" && this.schedule( /* wasError */ !0 ); return; } this.schedule(); } } /** * @license * Copyright 2020 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ class z { constructor(e, t) { this.createdAt = e, this.lastLoginAt = t, this._initializeTime(); } _initializeTime() { this.lastSignInTime = w(this.lastLoginAt), this.creationTime = w(this.createdAt); } _copy(e) { this.createdAt = e.createdAt, this.lastLoginAt = e.lastLoginAt, this._initializeTime(); } toJSON() { return { createdAt: this.createdAt, lastLoginAt: this.lastLoginAt }; } } /** * @license * Copyright 2019 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ async function R(i) { var e; const t = i.auth, r = await i.getIdToken(), n = await V(i, b(t, { idToken: r })); u( n == null ? void 0 : n.users.length, t, "internal-error" /* AuthErrorCode.INTERNAL_ERROR */ ); const s = n.users[0]; i._notifyReloadListener(s); const a = !((e = s.providerUserInfo) === null || e === void 0) && e.length ? Ae(s.providerUserInfo) : [], c = Ze(i.providerData, a), o = i.isAnonymous, l = !(i.email && s.passwordHash) && !(c != null && c.length), d = o ? l : !1, p = { uid: s.localId, displayName: s.displayName || null, photoURL: s.photoUrl || null, email: s.email || null, emailVerified: s.emailVerified || !1, phoneNumber: s.phoneNumber || null, tenantId: s.tenantId || null, providerData: c, metadata: new z(s.createdAt, s.lastLoginAt), isAnonymous: d }; Object.assign(i, p); } async function Qe(i) { const e = A(i); await R(e), await e.auth._persistUserIfCurrent(e), e.auth._notifyListenersIfCurrent(e); } function Ze(i, e) { return [...i.filter((r) => !e.some((n) => n.providerId === r.providerId)), ...e]; } function Ae(i) { return i.map((e) => { var { providerId: t } = e, r = fe(e, ["providerId"]); return { providerId: t, uid: r.rawId || "", displayName: r.displayName || null, email: r.email || null, phoneNumber: r.phoneNumber || null, photoURL: r.photoUrl || null }; }); } /** * @license * Copyright 2020 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ async function et(i, e) { const t = await ye(i, {}, async () => { const r = he({ grant_type: "refresh_token", refresh_token: e }).slice(1), { tokenApiHost: n, apiKey: s } = i.config, a = await Te(i, n, "/v1/token", `key=${s}`), c = await i._getAdditionalHeaders(); return c[ "Content-Type" /* HttpHeader.CONTENT_TYPE */ ] = "application/x-www-form-urlencoded", Ie.fetch()(a, { method: "POST", headers: c, body: r }); }); return { accessToken: t.access_token, expiresIn: t.expires_in, refreshToken: t.refresh_token }; } async function tt(i, e) { return U(i, "POST", "/v2/accounts:revokeToken", ve(i, e)); } /** * @license * Copyright 2020 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ class I { constructor() { this.refreshToken = null, this.accessToken = null, this.expirationTime = null; } get isExpired() { return !this.expirationTime || Date.now() > this.expirationTime - 3e4; } updateFromServerResponse(e) { u( e.idToken, "internal-error" /* AuthErrorCode.INTERNAL_ERROR */ ), u( typeof e.idToken < "u", "internal-error" /* AuthErrorCode.INTERNAL_ERROR */ ), u( typeof e.refreshToken < "u", "internal-error" /* AuthErrorCode.INTERNAL_ERROR */ ); const t = "expiresIn" in e && typeof e.expiresIn < "u" ? Number(e.expiresIn) : re(e.idToken); this.updateTokensAndExpiration(e.idToken, e.refreshToken, t); } updateFromIdToken(e) { u( e.length !== 0, "internal-error" /* AuthErrorCode.INTERNAL_ERROR */ ); const t = re(e); this.updateTokensAndExpiration(e, null, t); } async getToken(e, t = !1) { return !t && this.accessToken && !this.isExpired ? this.accessToken : (u( this.refreshToken, e, "user-token-expired" /* AuthErrorCode.TOKEN_EXPIRED */ ), this.refreshToken ? (await this.refresh(e, this.refreshToken), this.accessToken) : null); } clearRefreshToken() { this.refreshToken = null; } async refresh(e, t) { const { accessToken: r, refreshToken: n, expiresIn: s } = await et(e, t); this.updateTokensAndExpiration(r, n, Number(s)); } updateTokensAndExpiration(e, t, r) { this.refreshToken = t || null, this.accessToken = e || null, this.expirationTime = Date.now() + r * 1e3; } static fromJSON(e, t) { const { refreshToken: r, accessToken: n, expirationTime: s } = t, a = new I(); return r && (u(typeof r == "string", "internal-error", { appName: e }), a.refreshToken = r), n && (u(typeof n == "string", "internal-error", { appName: e }), a.accessToken = n), s && (u(typeof s == "number", "internal-error", { appName: e }), a.expirationTime = s), a; } toJSON() { return { refreshToken: this.refreshToken, accessToken: this.accessToken, expirationTime: this.expirationTime }; } _assign(e) { this.accessToken = e.accessToken, this.refreshToken = e.refreshToken, this.expirationTime = e.expirationTime; } _clone() { return Object.assign(new I(), this.toJSON()); } _performRefresh() { return T("not implemented"); } } /** * @license * Copyright 2020 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ function m(i, e) { u(typeof i == "string" || typeof i > "u", "internal-error", { appName: e }); } class h { constructor(e) { var { uid: t, auth: r, stsTokenManager: n } = e, s = fe(e, ["uid", "auth", "stsTokenManager"]); this.providerId = "firebase", this.proactiveRefresh = new Ye(this), this.reloadUserInfo = null, this.reloadListener = null, this.uid = t, this.auth = r, this.stsTokenManager = n, this.accessToken = n.accessToken, this.displayName = s.displayName || null, this.email = s.email || null, this.emailVerified = s.emailVerified || !1, this.phoneNumber = s.phoneNumber || null, this.photoURL = s.photoURL || null, this.isAnonymous = s.isAnonymous || !1, this.tenantId = s.tenantId || null, this.providerData = s.providerData ? [...s.providerData] : [], this.metadata = new z(s.createdAt || void 0, s.lastLoginAt || void 0); } async getIdToken(e) { const t = await V(this, this.stsTokenManager.getToken(this.auth, e)); return u( t, this.auth, "internal-error" /* AuthErrorCode.INTERNAL_ERROR */ ), this.accessToken !== t && (this.accessToken = t, await this.auth._persistUserIfCurrent(this), this.auth._notifyListenersIfCurrent(this)), t; } getIdTokenResult(e) { return Be(this, e); } reload() { return Qe(this); } _assign(e) { this !== e && (u( this.uid === e.uid, this.auth, "internal-error" /* AuthErrorCode.INTERNAL_ERROR */ ), this.displayName = e.displayName, this.photoURL = e.photoURL, this.email = e.email, this.emailVerified = e.emailVerified, this.phoneNumber = e.phoneNumber, this.isAnonymous = e.isAnonymous, this.tenantId = e.tenantId, this.providerData = e.providerData.map((t) => Object.assign({}, t)), this.metadata._copy(e.metadata), this.stsTokenManager._assign(e.stsTokenManager)); } _clone(e) { const t = new h(Object.assign(Object.assign({}, this), { auth: e, stsTokenManager: this.stsTokenManager._clone() })); return t.metadata._copy(this.metadata), t; } _onReload(e) { u( !this.reloadListener, this.auth, "internal-error" /* AuthErrorCode.INTERNAL_ERROR */ ), this.reloadListener = e, this.reloadUserInfo && (this._notifyReloadListener(this.reloadUserInfo), this.reloadUserInfo = null); } _notifyReloadListener(e) { this.reloadListener ? this.reloadListener(e) : this.reloadUserInfo = e; } _startProactiveRefresh() { this.proactiveRefresh._start(); } _stopProactiveRefresh() { this.proactiveRefresh._stop(); } async _updateTokensIfNecessary(e, t = !1) { let r = !1; e.idToken && e.idToken !== this.stsTokenManager.accessToken && (this.stsTokenManager.updateFromServerResponse(e), r = !0), t && await R(this), await this.auth._persistUserIfCurrent(this), r && this.auth._notifyListenersIfCurrent(this); } async delete() { if (g(this.auth.app)) return Promise.reject(E(this.auth)); const e = await this.getIdToken(); return await V(this, Je(this.auth, { idToken: e })), this.stsTokenManager.clearRefreshToken(), this.auth.signOut(); } toJSON() { return Object.assign(Object.assign({ uid: this.uid, email: this.email || void 0, emailVerified: this.emailVerified, displayName: this.displayName || void 0, isAnonymous: this.isAnonymous, photoURL: this.photoURL || void 0, phoneNumber: this.phoneNumber || void 0, tenantId: this.tenantId || void 0, providerData: this.providerData.map((e) => Object.assign({}, e)), stsTokenManager: this.stsTokenManager.toJSON(), // Redirect event ID must be maintained in case there is a pending // redirect event. _redirectEventId: this._redirectEventId }, this.metadata.toJSON()), { // Required for compatibility with the legacy SDK (go/firebase-auth-sdk-persistence-parsing): apiKey: this.auth.config.apiKey, appName: this.auth.name }); } get refreshToken() { return this.stsTokenManager.refreshToken || ""; } static _fromJSON(e, t) { var r, n, s, a, c, o, l, d; const p = (r = t.displayName) !== null && r !== void 0 ? r : void 0, y = (n = t.email) !== null && n !== void 0 ? n : void 0, W = (s = t.phoneNumber) !== null && s !== void 0 ? s : void 0, G = (a = t.photoURL) !== null && a !== void 0 ? a : void 0, j = (c = t.tenantId) !== null && c !== void 0 ? c : void 0, O = (o = t._redirectEventId) !== null && o !== void 0 ? o : void 0, q = (l = t.createdAt) !== null && l !== void 0 ? l : void 0, J = (d = t.lastLoginAt) !== null && d !== void 0 ? d : void 0, { uid: L, emailVerified: B, isAnonymous: X, providerData: M, stsTokenManager: Y } = t; u( L && Y, e, "internal-error" /* AuthErrorCode.INTERNAL_ERROR */ ); const Ne = I.fromJSON(this.name, Y); u( typeof L == "string", e, "internal-error" /* AuthErrorCode.INTERNAL_ERROR */ ), m(p, e.name), m(y, e.name), u( typeof B == "boolean", e, "internal-error" /* AuthErrorCode.INTERNAL_ERROR */ ), u( typeof X == "boolean", e, "internal-error" /* AuthErrorCode.INTERNAL_ERROR */ ), m(W, e.name), m(G, e.name), m(j, e.name), m(O, e.name), m(q, e.name), m(J, e.name); const D = new h({ uid: L, auth: e, email: y, emailVerified: B, displayName: p, isAnonymous: X, photoURL: G, phoneNumber: W, tenantId: j, stsTokenManager: Ne, createdAt: q, lastLoginAt: J }); return M && Array.isArray(M) && (D.providerData = M.map((Ee) => Object.assign({}, Ee))), O && (D._redirectEventId = O), D; } /** * Initialize a User from an idToken server response * @param auth * @param idTokenResponse */ static async _fromIdTokenResponse(e, t, r = !1) { const n = new I(); n.updateFromServerResponse(t); const s = new h({ uid: t.localId, auth: e, stsTokenManager: n, isAnonymous: r }); return await R(s), s; } /** * Initialize a User from an idToken server response * @param auth * @param idTokenResponse */ static async _fromGetAccountInfoResponse(e, t, r) { const n = t.users[0]; u( n.localId !== void 0, "internal-error" /* AuthErrorCode.INTERNAL_ERROR */ ); const s = n.providerUserInfo !== void 0 ? Ae(n.providerUserInfo) : [], a = !(n.email && n.passwordHash) && !(s != null && s.length), c = new I(); c.updateFromIdToken(r); const o = new h({ uid: n.localId, auth: e, stsTokenManager: c, isAnonymous: a }), l = { uid: n.localId, displayName: n.displayName || null, photoURL: n.photoUrl || null, email: n.email || null, emailVerified: n.emailVerified || !1, phoneNumber: n.phoneNumber || null, tenantId: n.tenantId || null, providerData: s, metadata: new z(n.createdAt, n.lastLoginAt), isAnonymous: !(n.email && n.passwordHash) && !(s != null && s.length) }; return Object.assign(o, l), o; } } /** * @license * Copyright 2020 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ const ne = /* @__PURE__ */ new Map(); function _(i) { C(i instanceof Function, "Expected a class definition"); let e = ne.get(i); return e ? (C(e instanceof i, "Instance stored in cache mismatched with class"), e) : (e = new i(), ne.set(i, e), e); } /** * @license * Copyright 2019 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ class ke { constructor() { this.type = "NONE", this.storage = {}; } async _isAvailable() { return !0; } async _set(e, t) { this.storage[e] = t; } async _get(e) { const t = this.storage[e]; return t === void 0 ? null : t; } async _remove(e) { delete this.storage[e]; } _addListener(e, t) { } _removeListener(e, t) { } } ke.type = "NONE"; const se = ke; /** * @license * Copyright 2019 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ function x(i, e, t) { return `firebase:${i}:${e}:${t}`; } class v { constructor(e, t, r) { this.persistence = e, this.auth = t, this.userKey = r; const { config: n, name: s } = this.auth; this.fullUserKey = x(this.userKey, n.apiKey, s), this.fullPersistenceKey = x("persistence", n.apiKey, s), this.boundEventHandler = t._onStorageEvent.bind(t), this.persistence._addListener(this.fullUserKey, this.boundEventHandler); } setCurrentUser(e) { return this.persistence._set(this.fullUserKey, e.toJSON()); } async getCurrentUser() { const e = await this.persistence._get(this.fullUserKey); if (!e) return null; if (typeof e == "string") { const t = await b(this.auth, { idToken: e }).catch(() => { }); return t ? h._fromGetAccountInfoResponse(this.auth, t, e) : null; } return h._fromJSON(this.auth, e); } removeCurrentUser() { return this.persistence._remove(this.fullUserKey); } savePersistenceForRedirect() { return this.persistence._set(this.fullPersistenceKey, this.persistence.type); } async setPersistence(e) { if (this.persistence === e) return; const t = await this.getCurrentUser(); if (await this.removeCurrentUser(), this.persistence = e, t) return this.setCurrentUser(t); } delete() { this.persistence._removeListener(this.fullUserKey, this.boundEventHandler); } static async create(e, t, r = "authUser") { if (!t.length) return new v(_(se), e, r); const n = (await Promise.all(t.map(async (l) => { if (await l._isAvailable()) return l; }))).filter((l) => l); let s = n[0] || _(se); const a = x(r, e.config.apiKey, e.name); let c = null; for (const l of t) try { const d = await l._get(a); if (d) { let p; if (typeof d == "string") { const y = await b(e, { idToken: d }).catch(() => { }); if (!y) break; p = await h._fromGetAccountInfoResponse(e, y, d); } else p = h._fromJSON(e, d); l !== s && (c = p), s = l; break; } } catch { } const o = n.filter((l) => l._shouldAllowMigration); return !s._shouldAllowMigration || !o.length ? new v(s, e, r) : (s = o[0], c && await s._set(a, c.toJSON()), await Promise.all(t.map(async (l) => { if (l !== s) try { await l._remove(a); } catch { } })), new v(s, e, r)); } } /** * @license * Copyright 2020 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ function ae(i) { const e = i.toLowerCase(); if (e.includes("opera/") || e.includes("opr/") || e.includes("opios/")) return "Opera"; if (st(e)) return "IEMobile"; if (e.includes("msie") || e.includes("trident/")) return "IE"; if (e.includes("edge/")) return "Edge"; if (it(e)) return "Firefox"; if (e.includes("silk/")) return "Silk"; if (ot(e)) return "Blackberry"; if (ct(e)) return "Webos"; if (rt(e)) return "Safari"; if ((e.includes("chrome/") || nt(e)) && !e.includes("edge/")) return "Chrome"; if (at(e)) return "Android"; { const t = /([a-zA-Z\d\.]+)\/[a-zA-Z\d\.]*$/, r = i.match(t); if ((r == null ? void 0 : r.length) === 2) return r[1]; } return "Other"; } function it(i = f()) { return /firefox\//i.test(i); } function rt(i = f()) { const e = i.toLowerCase(); return e.includes("safari/") && !e.includes("chrome/") && !e.includes("crios/") && !e.includes("android"); } function nt(i = f()) { return /crios\//i.test(i); } function st(i = f()) { return /iemobile/i.test(i); } function at(i = f()) { return /android/i.test(i); } function ot(i = f()) { return /blackberry/i.test(i); } function ct(i = f()) { return /webos/i.test(i); } /** * @license * Copyright 2020 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ function Se(i, e = []) { let t; switch (i) { case "Browser": t = ae(f()); break; case "Worker": t = `${ae(f())}-${i}`; break; default: t = i; } const r = e.length ? e.join(",") : "FirebaseCore-web"; return `${t}/JsCore/${H}/${r}`; } /** * @license * Copyright 2022 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ class ut { constructor(e) { this.auth = e, this.queue = []; } pushCallback(e, t) { const r = (s) => new Promise((a, c) => { try { const o = e(s); a(o); } catch (o) { c(o); } }); r.onAbort = t, this.queue.push(r); const n = this.queue.length - 1; return () => { this.queue[n] = () => Promise.resolve(); }; } async runMiddleware(e) { if (this.auth.currentUser === e) return; const t = []; try { for (const r of this.queue) await r(e), r.onAbort && t.push(r.onAbort); } catch (r) { t.reverse(); for (const n of t) try { n(); } catch { } throw this.auth._errorFactory.create("login-blocked", { originalMessage: r == null ? void 0 : r.message }); } } } /** * @license * Copyright 2023 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ async function lt(i, e = {}) { return U(i, "GET", "/v2/passwordPolicy", ve(i, e)); } /** * @license * Copyright 2023 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ const dt = 6; class ht { constructor(e) { var t, r, n, s; const a = e.customStrengthOptions; this.customStrengthOptions = {}, this.customStrengthOptions.minPasswordLength = (t = a.minPasswordLength) !== null && t !== void 0 ? t : dt, a.maxPasswordLength && (this.customStrengthOptions.maxPasswordLength = a.maxPasswordLength), a.containsLowercaseCharacter !== void 0 && (this.customStrengthOptions.containsLowercaseLetter = a.containsLowercaseCharacter), a.containsUppercaseCharacter !== void 0 && (this.customStrengthOptions.containsUppercaseLetter = a.containsUppercaseCharacter), a.containsNumericCharacter !== void 0 && (this.customStrengthOptions.containsNumericCharacter = a.containsNumericCharacter), a.containsNonAlphanumericCharacter !== void 0 && (this.customStrengthOptions.containsNonAlphanumericCharacter = a.containsNonAlphanumericCharacter), this.enforcementState = e.enforcementState, this.enforcementState === "ENFORCEMENT_STATE_UNSPECIFIED" && (this.enforcementState = "OFF"), this.allowedNonAlphanumericCharacters = (n = (r = e.allowedNonAlphanumericCharacters) === null || r === void 0 ? void 0 : r.join("")) !== null && n !== void 0 ? n : "", this.forceUpgradeOnSignin = (s = e.forceUpgradeOnSignin) !== null && s !== void 0 ? s : !1, this.schemaVersion = e.schemaVersion; } validatePassword(e) { var t, r, n, s, a, c; const o = { isValid: !0, passwordPolicy: this }; return this.validatePasswordLengthOptions(e, o), this.validatePasswordCharacterOptions(e, o), o.isValid && (o.isValid = (t = o.meetsMinPasswordLength) !== null && t !== void 0 ? t : !0), o.isValid && (o.isValid = (r = o.meetsMaxPasswordLength) !== null && r !== void 0 ? r : !0), o.isValid && (o.isValid = (n = o.containsLowercaseLetter) !== null && n !== void 0 ? n : !0), o.isValid && (o.isValid = (s = o.containsUppercaseLetter) !== null && s !== void 0 ? s : !0), o.isValid && (o.isValid = (a = o.containsNumericCharacter) !== null && a !== void 0 ? a : !0), o.isValid && (o.isValid = (c = o.containsNonAlphanumericCharacter) !== null && c !== void 0 ? c : !0), o; } /** * Validates that the password meets the length options for the policy. * * @param password Password to validate. * @param status Validation status. */ validatePasswordLengthOptions(e, t) { const r = this.customStrengthOptions.minPasswordLength, n = this.customStrengthOptions.maxPasswordLength; r && (t.meetsMinPasswordLength = e.length >= r), n && (t.meetsMaxPasswordLength = e.length <= n); } /** * Validates that the passwo