trying to fix protected route data fetch problem and only one more problem somewhere in the
This commit is contained in:
@@ -30,7 +30,7 @@ export default function CreateConversation() {
|
|||||||
const { currUser } = useAuth();
|
const { currUser } = useAuth();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
const input = useRef<HTMLInputElement>();
|
const input = useRef<HTMLInputElement>(null);
|
||||||
|
|
||||||
const [selectedUsers, setSelectedUsers] = useState<User[]>([] as User[]);
|
const [selectedUsers, setSelectedUsers] = useState<User[]>([] as User[]);
|
||||||
const [isLoading, setIsLoading] = useState<boolean>(false);
|
const [isLoading, setIsLoading] = useState<boolean>(false);
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ export default function Header() {
|
|||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
const inputRef = useRef<HTMLInputElement | undefined>();
|
const inputRef = useRef<HTMLInputElement>(null);
|
||||||
|
|
||||||
const [searchInput, setSearchInput] = useState<string>("");
|
const [searchInput, setSearchInput] = useState<string>("");
|
||||||
|
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ export default function ViewConvo(props: { conversationId: string }) {
|
|||||||
|
|
||||||
const allConvosMap = useRecoilValue(allRelevantConversationsAtom);
|
const allConvosMap = useRecoilValue(allRelevantConversationsAtom);
|
||||||
|
|
||||||
const endOfTimeline = useRef<HTMLSpanElement>();
|
const endOfTimeline = useRef<HTMLSpanElement>(null);
|
||||||
|
|
||||||
const [currentConvoModal, setCurrConvoModal] = useState<ConvoModal>(
|
const [currentConvoModal, setCurrConvoModal] = useState<ConvoModal>(
|
||||||
ConvoModal.na
|
ConvoModal.na
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { User } from "@nirvana/common/models/user";
|
import User from "@nirvana/common/models/user";
|
||||||
import { useAuth } from "../../contexts/authContext";
|
import { useAuth } from "../../contexts/authContext";
|
||||||
import { useRecoilValue, useRecoilState } from "recoil";
|
import { useRecoilValue, useRecoilState } from "recoil";
|
||||||
import { allRelevantContactsAtom } from "../../recoil/main";
|
import { allRelevantContactsAtom } from "../../recoil/main";
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
import { useRouter } from "next/router";
|
||||||
|
import toast from "react-hot-toast";
|
||||||
|
import { useAuth } from "./authContext";
|
||||||
|
import { useEffect } from "react";
|
||||||
|
|
||||||
|
export default function ProtectedRoute({ children }) {
|
||||||
|
const { currUser } = useAuth();
|
||||||
|
|
||||||
|
// figure out what content to render from here
|
||||||
|
const router = useRouter();
|
||||||
|
|
||||||
|
// useEffect(() => {}, []);
|
||||||
|
|
||||||
|
if (!currUser) {
|
||||||
|
console.log("not authenticated...routing from dashboard to teams home");
|
||||||
|
toast.error("Not Authenticated");
|
||||||
|
router.push("/teams/login");
|
||||||
|
return <></>;
|
||||||
|
}
|
||||||
|
|
||||||
|
return <>{currUser && children}</>;
|
||||||
|
}
|
||||||
@@ -26,13 +26,15 @@ function MyApp({ Component, pageProps }: AppPropsWithLayout) {
|
|||||||
const getLayout = Component.getLayout ?? ((page) => page);
|
const getLayout = Component.getLayout ?? ((page) => page);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<RecoilRoot>
|
<AuthProvider>
|
||||||
<SiteLayout>
|
<RecoilRoot>
|
||||||
<AuthProvider>{getLayout(<Component {...pageProps} />)}</AuthProvider>
|
<SiteLayout>
|
||||||
|
{getLayout(<Component {...pageProps} />)}
|
||||||
|
|
||||||
<Toaster position="top-center" />
|
<Toaster position="top-center" />
|
||||||
</SiteLayout>
|
</SiteLayout>
|
||||||
</RecoilRoot>
|
</RecoilRoot>
|
||||||
|
</AuthProvider>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,20 +16,13 @@ import ViewConvo from "../../components/MainTabsOrPages/ViewConvo";
|
|||||||
import MainRecoilDataHandler from "../../recoil/MainRecoilDataHandler";
|
import MainRecoilDataHandler from "../../recoil/MainRecoilDataHandler";
|
||||||
import { useAuth } from "../../contexts/authContext";
|
import { useAuth } from "../../contexts/authContext";
|
||||||
import AudioHandler from "../../components/Audio/AudioHandler";
|
import AudioHandler from "../../components/Audio/AudioHandler";
|
||||||
|
import toast from "react-hot-toast";
|
||||||
|
import ProtectedRoute from "../../contexts/ProtectedRoute";
|
||||||
|
|
||||||
export default function Me() {
|
export default function Me() {
|
||||||
// TODO: if not authenticated, take user away
|
|
||||||
const { currUser } = useAuth();
|
|
||||||
useEffect(() => {
|
|
||||||
if (!currUser) {
|
|
||||||
console.log("not authenticated...routing from dashboard to teams home");
|
|
||||||
router.push("/teams/login");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
// figure out what content to render from here
|
// figure out what content to render from here
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
const currPage = router.query.page;
|
const currPage = router.query.page;
|
||||||
const currConvo = router.query.convoId;
|
const currConvo = router.query.convoId;
|
||||||
|
|
||||||
@@ -128,15 +121,17 @@ export default function Me() {
|
|||||||
Me.getLayout = function (content: ReactElement) {
|
Me.getLayout = function (content: ReactElement) {
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col">
|
<div className="flex flex-col">
|
||||||
<MainRecoilDataHandler />
|
<ProtectedRoute>
|
||||||
|
<MainRecoilDataHandler />
|
||||||
|
|
||||||
<KeyboardShortcutHandler />
|
<KeyboardShortcutHandler />
|
||||||
|
|
||||||
<Header />
|
<Header />
|
||||||
|
|
||||||
{content}
|
{content}
|
||||||
|
|
||||||
<AudioHandler />
|
<AudioHandler />
|
||||||
|
</ProtectedRoute>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user