Files
MyIP/frontend/firebase-init.js
T
Claude 96525d2fc7 Chore: trim the branch — leftovers, redundancy, comments
A pass over every file the branch touched, after the iOS animation hunt
left tries and reverts behind it. Removed what nothing reaches: the
view-transition rule for a transition no code starts, an unreachable
guard in the transition hook, a no-op KeepAlive key branch, a sign-in
guard the menu already enforces, usage-dialog wrappers that only
forwarded to the store, a duplicated modifier-click check and card
filter (isPlainClick / listedTools), a test that hand-rolled
listedTools, a drawer-era fixture parameter. auth-flow.js folded into
auth-redirect.js. Comments cut to what the code cannot say itself —
file headers of a few lines, the measured iOS reasons, non-obvious
orderings — and stale ones fixed (Nav under KeepAlive, Home.vue
reusing DEFAULT_META, "from Nav", enabledCards). AGENTS.md sections
tightened to the code as it is now.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013GbLTGMZ45MV78qd2tHoco
2026-10-05 16:50:16 +00:00

52 lines
2.1 KiB
JavaScript

// Firebase Auth bootstrap — env-gated AND lazy: the SDK chunk only loads on
// the first loadFirebaseAuth() call (signed-in boot, sign-in click, or the
// background auth probe), never on the visitor-critical path.
import { resolveAuthDomain } from './utils/auth-domain.js';
import { isRunningAsPwa } from './utils/pwa.js';
const env = import.meta.env ?? {};
const isFireBaseSet = !!env.VITE_FIREBASE_API_KEY && !!env.VITE_FIREBASE_AUTH_DOMAIN && !!env.VITE_FIREBASE_PROJECT_ID;
// Inputs for utils/auth-domain.js, read on demand (display mode needs `window`).
const authDomainInputs = () => ({
runningAsPwa: isRunningAsPwa(),
authDomain: env.VITE_FIREBASE_AUTH_DOMAIN,
pwaAuthDomain: env.VITE_FIREBASE_PWA_AUTH_DOMAIN,
});
let authModulePromise = null;
// Resolves to the firebase/auth namespace plus the initialized `auth`
// instance (memoized), or null when the env isn't configured.
const loadFirebaseAuth = () => {
if (!isFireBaseSet) return Promise.resolve(null);
authModulePromise ??= Promise.all([
import('firebase/app'),
import('firebase/auth'),
]).then(([appModule, authModule]) => {
// Hostile client environments (extensions, filtered networks) can
// resolve a dynamic import to undefined instead of rejecting —
// convert that to a readable rejection so the retry path below runs.
if (!appModule?.initializeApp || !authModule?.getAuth) {
throw new Error('Firebase modules resolved without expected exports');
}
return {
...authModule,
auth: authModule.getAuth(appModule.initializeApp({
apiKey: env.VITE_FIREBASE_API_KEY,
authDomain: resolveAuthDomain(authDomainInputs()),
projectId: env.VITE_FIREBASE_PROJECT_ID,
})),
};
}).catch((error) => {
// Don't memoize a transient chunk-load failure — the next auth
// action should retry the import instead of replaying the rejection.
authModulePromise = null;
throw error;
});
return authModulePromise;
};
export { loadFirebaseAuth, authDomainInputs };