From c528bad456632f5d7176ed6692e6da388be98417 Mon Sep 17 00:00:00 2001 From: Jack Hansen <47556286+jackavh@users.noreply.github.com> Date: Wed, 22 May 2024 18:51:57 -0700 Subject: [PATCH] lint fixes and re-add firebase provider (messed with merge) --- .../app/admin/firebase/firebaseProvider.tsx | 32 +++++++++++++++++++ frontend/src/components/UserIcon.tsx | 4 +-- 2 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 frontend/src/app/admin/firebase/firebaseProvider.tsx diff --git a/frontend/src/app/admin/firebase/firebaseProvider.tsx b/frontend/src/app/admin/firebase/firebaseProvider.tsx new file mode 100644 index 00000000..718db045 --- /dev/null +++ b/frontend/src/app/admin/firebase/firebaseProvider.tsx @@ -0,0 +1,32 @@ +"use client"; + +import { Auth } from "firebase/auth"; +import { FirebaseStorage } from "firebase/storage"; +import React, { FC, ReactNode, createContext, useContext, useEffect, useState } from "react"; + +import { FirebaseServices, initFirebase } from "./firebase"; + +const AuthContext = createContext(undefined); +const StorageContext = createContext(undefined); + +export const FirebaseProvider: FC<{ children: ReactNode }> = ({ children }) => { + const [firebaseServices, setFirebaseServices] = useState(undefined); + + useEffect(() => { + // Don't initialize Firebase if it has already been initialized + if (firebaseServices === undefined) { + setFirebaseServices(initFirebase()); + } + }, []); + + return ( + + + {children} + + + ); +}; + +export const useAuth = () => useContext(AuthContext); +export const useStorage = () => useContext(StorageContext); diff --git a/frontend/src/components/UserIcon.tsx b/frontend/src/components/UserIcon.tsx index 8293151c..725d2497 100644 --- a/frontend/src/components/UserIcon.tsx +++ b/frontend/src/components/UserIcon.tsx @@ -10,12 +10,12 @@ import { useRouter } from "next/navigation"; import * as React from "react"; import { firebaseSignOut } from "@/app/admin/firebase/firebase"; -import { useFirebase } from "@/app/admin/firebase/firebaseProvider"; +import { useAuth } from "@/app/admin/firebase/firebaseProvider"; export default function UserIcon() { const [anchorEl, setAnchorEl] = React.useState(null); const open = Boolean(anchorEl); - const auth = useFirebase().auth; + const auth = useAuth(); const router = useRouter(); const handleClick = (event: React.MouseEvent) => {