tubearchivist-frontend/src/pages/index.tsx
2022-04-22 12:34:56 -05:00

47 lines
1.0 KiB
TypeScript

import type { GetServerSideProps, NextPage } from "next";
import { getSession } from "next-auth/react";
import { dehydrate, QueryClient } from "react-query";
import { CustomHead } from "../components/CustomHead";
import { Layout } from "../components/Layout";
import VideoList from "../components/VideoList/";
import { getVideos } from "../lib/getVideos";
const Home: NextPage = () => {
return (
<>
<CustomHead />
<Layout>
<VideoList />
</Layout>
</>
);
};
export default Home;
export const getServerSideProps: GetServerSideProps = async (context) => {
const queryClient = new QueryClient();
const session = await getSession(context);
if (!session) {
return {
redirect: {
destination: "/auth/login",
permanent: false,
},
};
}
await queryClient.prefetchQuery(["videos", session.ta_token.token], () =>
getVideos(session.ta_token.token)
);
return {
props: {
dehydratedState: dehydrate(queryClient),
session,
},
};
};