From e5546a62aa37a5dd84395fa264bffaec84bb1aa5 Mon Sep 17 00:00:00 2001 From: Arjun Patel Date: Tue, 18 Jan 2022 14:25:23 -0800 Subject: [PATCH] fixing sign out issues --- components/Dashboard/Header.tsx | 2 -- components/Modals/PowerPlayer.tsx | 18 +++++++++++++++++- contexts/authContext.js | 14 ++++++++++++-- contexts/teamDashboardContext.tsx | 15 +++++++++++++-- 4 files changed, 42 insertions(+), 7 deletions(-) diff --git a/components/Dashboard/Header.tsx b/components/Dashboard/Header.tsx index cb95afe..1d7f386 100644 --- a/components/Dashboard/Header.tsx +++ b/components/Dashboard/Header.tsx @@ -82,8 +82,6 @@ export default function Header() { try { await logOut(); - - router.push("/teams/landing"); } catch (error) { console.log(error); toast.error("Unable to log out!"); diff --git a/components/Modals/PowerPlayer.tsx b/components/Modals/PowerPlayer.tsx index ce93672..fb8568a 100644 --- a/components/Modals/PowerPlayer.tsx +++ b/components/Modals/PowerPlayer.tsx @@ -41,8 +41,24 @@ export default function PowerPlayer(props: { handleAddAudioToQueue([url]); } + function handleClose(e) { + props.handleCloseModal(); + } + return ( - + + 👋 Close + + } + > One timeline to listen to the past 24 hours. diff --git a/contexts/authContext.js b/contexts/authContext.js index c883e92..7a2d999 100644 --- a/contexts/authContext.js +++ b/contexts/authContext.js @@ -6,8 +6,10 @@ import { signOut, User, } from "firebase/auth"; +import { useRouter } from "next/router"; import React, { useContext, useEffect, useState } from "react"; import toast from "react-hot-toast"; +import Loading from "../components/Loading"; import firebase from "../services/firebaseService"; const AuthContext = React.createContext(null); @@ -19,8 +21,12 @@ export function AuthProvider({ children }) { const [currUser, setCurrUser] = useState(); const [loading, setLoading] = useState(true); + const router = useRouter(); + useEffect(() => { const unsubscribe = onAuthStateChanged(auth, async (user) => { + setLoading(true); + console.log("change in auth"); if (user) { setCurrUser(user); @@ -67,10 +73,14 @@ export function AuthProvider({ children }) { }); }; - const logOut = () => { + const logOut = async () => { + setLoading(true); + console.log("logging user out"); - return signOut(auth); + Promise.resolve(await signOut(auth)); + + router.push("/teams/landing"); }; const value = { diff --git a/contexts/teamDashboardContext.tsx b/contexts/teamDashboardContext.tsx index a9964f9..abb51ee 100644 --- a/contexts/teamDashboardContext.tsx +++ b/contexts/teamDashboardContext.tsx @@ -50,8 +50,11 @@ const db = getFirestore(); export function TeamDashboardContextProvider({ children }) { const { currUser } = useAuth(); - const [loading, setLoading] = useState(true); + const router = useRouter(); + + const [loading, setLoading] = useState(true); + const { teamid } = router.query; // this context can only be used if it's a specific route: '/teams' @@ -212,7 +215,9 @@ export function TeamDashboardContextProvider({ children }) { })(); return () => { - userListener(); + if (userListener) { + userListener(); + } unsubs.forEach((unsub) => { unsub(); @@ -232,6 +237,12 @@ export function TeamDashboardContextProvider({ children }) { useEffect(() => { // todo for new messages, change document.title + if (!currUser) { + console.log("not authenticated...routing from dashboard to teams home"); + router.push("/teams/login"); + return; + } + /** * QUERY: * - last 24 hours only