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C,EAAAA,EAAAA,IAAmBpB,EAAK,CACvCqB,SAAU,IAAIC,EAAAA,GACZJ,4CAKFK,2BAA2B,IAY7B,MATA,WACE,MAAMC,QAAcC,EAAAA,EAAAA,IAASN,GAI7BJ,OAAOW,MAAQX,OAAOW,OAAS,GAE/BX,OAAOW,MAAMC,UAAYH,EAAMA,OAPjC,GASOL,EAASnB,OAIjB,CAACnB,EAAOW,EAAgBC,IAE3B,OAAO,QAACf,EAAmBW,SAApB,KAA6BC,MAAOI,GAAiBb,GAArD,wGClJT,MAAM+C,EACJV,+RAOF,MAAMW,EAAgC,IAAkB,IAAjB,SAAEC,GAAe,EACtD,MAAM,EAAC/C,EAAD,EAAMC,IAAUC,EAAAA,EAAAA,UAAsB,MAO5C,OANAC,EAAAA,EAAAA,YAAU,KACR,WACE,MAAM6C,QAAa3C,EAAAA,EAAAA,KACnBJ,EAAO+C,IAFT,MAKS,MAAPhD,GACK,uBAAG+C,KAGL,QAACnD,EAAD,CAAcG,IAAKC,EAAnB,oHAAyB+C,KAG5BtC,EAAiBwC,KAAKC,MAAML,GAelC,MAN8B,QAAC,SAAEE,GAAH,SAC5B,QAACvC,EAAD,CAAqBC,eAAgBA,EAArC,oHACE,QAACqC,EAAD,oHAAsBC","sources":["webpack://_N_E/./src/auth/context.tsx","webpack://_N_E/./src/components/provider/AuthProvider/AuthProvider.tsx"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-unsafe-assignment */\n/* eslint-disable @typescript-eslint/no-unsafe-member-access */\n/* eslint-disable @typescript-eslint/ban-ts-comment */\nimport type { FirebaseApp, FirebaseOptions } from \"firebase/app\";\nimport { getApps, initializeApp, registerVersion } from \"firebase/app\";\nimport {\n getToken,\n initializeAppCheck,\n ReCaptchaV3Provider,\n} from \"firebase/app-check\";\nimport type { Auth } from \"firebase/auth\";\nimport {\n createContext,\n useContext,\n useEffect,\n useMemo,\n useState,\n version,\n} from \"react\";\n\nimport { getAuth } from \"#auth/utils\";\nimport { env } from \"#util/env\";\n\nconst AuthSdkContext = createContext<Auth | undefined>(undefined);\nconst FirebaseAppContext = createContext<FirebaseApp | undefined>(undefined);\n\n// Right now (and probably forever) we only support the Firebase Auth SDK\ntype FirebaseSdks = Auth;\n\n/**\n * @param SdkContext Take a (Firebase Auth) React Context\n * @returns (the Firebase Auth) Provider\n */\nfunction getSdkProvider<Sdk extends FirebaseSdks>(\n SdkContext: React.Context<Sdk | undefined>,\n) {\n return function SdkProvider(props: React.PropsWithChildren<{ sdk: Sdk }>) {\n const { sdk } = props;\n const [SDK, setSDK] = useState<Auth | undefined>(sdk);\n\n useEffect(() => {\n (async () => {\n const fbsdk = await getAuth();\n setSDK(fbsdk);\n })();\n }, []);\n\n if (!SDK) return null;\n\n return <SdkContext.Provider value={SDK as Sdk} {...props} />;\n };\n}\n\n/**\n * useAuth exposes the auth ref via context. This does not rerender when the auth\n * object is updated.\n */\nexport const AuthProvider = getSdkProvider<Auth>(AuthSdkContext);\n\n/**\n * Another glorified useContext for our firebase App\n */\nexport function useFirebaseApp() {\n const firebaseApp = useContext(FirebaseAppContext);\n if (!firebaseApp) {\n throw new Error(\n \"Cannot call useFirebaseApp unless your component is within a FirebaseAppProvider\",\n );\n }\n\n return firebaseApp;\n}\n\nconst shallowEq = <T,>(a: T, b: T) =>\n a === b ||\n (a != null &&\n b != null &&\n typeof a === \"object\" &&\n typeof b === \"object\" &&\n [...Object.keys(a), ...Object.keys(b)].every((key) => a[key] === b[key]));\n\ninterface FirebaseAppProviderProps {\n firebaseApp?: FirebaseApp;\n firebaseConfig?: FirebaseOptions;\n appName?: string;\n}\n\n/**\n * This Provider just memoizes our firebase app.\n */\nexport function FirebaseAppProvider(\n props: React.PropsWithChildren<FirebaseAppProviderProps>,\n) {\n const { firebaseConfig, appName } = props;\n\n const firebaseApp: FirebaseApp = useMemo(() => {\n const { firebaseApp: currentApp } = props;\n\n if (currentApp) {\n return currentApp;\n }\n\n const existingApp = getApps().find(\n (app) => app.name === (appName || \"tenet\"),\n );\n if (existingApp) {\n if (firebaseConfig && shallowEq(existingApp.options, firebaseConfig)) {\n return existingApp;\n }\n // Whoops?\n throw new Error(\n `Does not match the options already provided to the ${\n appName || \"default\"\n } firebase app instance, give this new instance a different appName.`,\n );\n }\n\n if (!firebaseConfig) {\n throw new Error(\"No firebaseConfig provided\");\n }\n\n const reactVersion = version || \"unknown\";\n registerVersion(\"react\", reactVersion);\n const app = initializeApp(firebaseConfig, appName);\n\n // see https://firebase.google.com/docs/app-check/web/recaptcha-provider for docs\n if (process.env.NEXT_PUBLIC_FIREBASE_RECAPTCHA) {\n if (!env.isProduction && !env.isQA) {\n // setup debug token for dev environments\n if (typeof window !== \"undefined\") {\n // @ts-ignore\n window.self.FIREBASE_APPCHECK_DEBUG_TOKEN =\n process.env.NEXT_PUBLIC_FIREBASE_APP_CHECK_DEBUG;\n }\n }\n\n const appCheck = initializeAppCheck(app, {\n provider: new ReCaptchaV3Provider(\n process.env.NEXT_PUBLIC_FIREBASE_RECAPTCHA,\n ),\n\n // Optional argument. If true, the SDK automatically refreshes App Check\n // tokens as needed.\n isTokenAutoRefreshEnabled: true,\n });\n\n (async () => {\n const token = await getToken(appCheck);\n // MPR, 2024/7/11: My patience with firebase nonsense has worn thin. We're doing this the brutal effective way.\n if (typeof window === \"undefined\") return;\n // @ts-ignore\n window.tenet = window.tenet || {};\n // @ts-ignore\n window.tenet.handshake = token.token;\n })();\n return appCheck.app;\n }\n\n return app;\n }, [props, firebaseConfig, appName]);\n\n return <FirebaseAppContext.Provider value={firebaseApp} {...props} />;\n}\n","import type { Auth } from \"firebase/auth\";\nimport { useEffect, useState } from \"react\";\n\nimport { AuthProvider, FirebaseAppProvider } from \"#auth/context\";\nimport { getAuth } from \"#auth/utils\";\n\ninterface FirebaseConfig {\n apiKey: string;\n appId: string;\n authDomain: string;\n messagingSenderId: string;\n projectId: string;\n storageBucket: string;\n}\n\nconst firebaseConfigJson: string | undefined =\n process.env.NEXT_PUBLIC_FIREBASE_CONFIG;\nif (!firebaseConfigJson) {\n throw Error(\n \"Cannot load firebase config - NEXT_PUBLIC_FIREBASE_CONFIG missing.\",\n );\n}\n\nconst WrappedAuthProvider: React.FC = ({ children }) => {\n const [SDK, setSDK] = useState<Auth | null>(null);\n useEffect(() => {\n (async () => {\n const auth = await getAuth();\n setSDK(auth);\n })();\n });\n if (SDK == null) {\n return <>{children}</>;\n }\n\n return <AuthProvider sdk={SDK}>{children}</AuthProvider>;\n};\n\nconst firebaseConfig = JSON.parse(firebaseConfigJson) as FirebaseConfig;\n\n/*\nconst AppProvider: React.FC = ({ children }) => (\n <FirebaseAppProvider firebaseConfig={firebaseConfig}>\n {children}\n </FirebaseAppProvider>\n);\n*/\nconst AppProvider: React.FC = ({ children }) => (\n <FirebaseAppProvider firebaseConfig={firebaseConfig}>\n <WrappedAuthProvider>{children}</WrappedAuthProvider>\n </FirebaseAppProvider>\n);\n\nexport default AppProvider;\n"],"names":["AuthSdkContext","createContext","undefined","FirebaseAppContext","AuthProvider","SdkContext","props","sdk","SDK","setSDK","useState","useEffect","fbsdk","getAuth","Provider","value","FirebaseAppProvider","firebaseConfig","appName","firebaseApp","useMemo","currentApp","existingApp","getApps","find","app","name","a","options","b","Object","keys","every","key","Error","reactVersion","version","registerVersion","initializeApp","env","window","self","FIREBASE_APPCHECK_DEBUG_TOKEN","process","appCheck","initializeAppCheck","provider","ReCaptchaV3Provider","isTokenAutoRefreshEnabled","token","getToken","tenet","handshake","firebaseConfigJson","WrappedAuthProvider","children","auth","JSON","parse"],"sourceRoot":""}