Skip to content

Commit

Permalink
lint fixes and re-add firebase provider (messed with merge)
Browse files Browse the repository at this point in the history
  • Loading branch information
jackavh committed May 23, 2024
1 parent dfc760d commit c528bad
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
32 changes: 32 additions & 0 deletions frontend/src/app/admin/firebase/firebaseProvider.tsx
Original file line number Diff line number Diff line change
@@ -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<Auth | undefined>(undefined);
const StorageContext = createContext<FirebaseStorage | undefined>(undefined);

export const FirebaseProvider: FC<{ children: ReactNode }> = ({ children }) => {
const [firebaseServices, setFirebaseServices] = useState<FirebaseServices | undefined>(undefined);

useEffect(() => {
// Don't initialize Firebase if it has already been initialized
if (firebaseServices === undefined) {
setFirebaseServices(initFirebase());
}
}, []);

return (
<AuthContext.Provider value={firebaseServices?.auth}>
<StorageContext.Provider value={firebaseServices?.storage}>
{children}
</StorageContext.Provider>
</AuthContext.Provider>
);
};

export const useAuth = () => useContext(AuthContext);
export const useStorage = () => useContext(StorageContext);
4 changes: 2 additions & 2 deletions frontend/src/components/UserIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 | HTMLElement>(null);
const open = Boolean(anchorEl);
const auth = useFirebase().auth;
const auth = useAuth();
const router = useRouter();

const handleClick = (event: React.MouseEvent<HTMLElement>) => {
Expand Down

0 comments on commit c528bad

Please sign in to comment.