2022-04-13 18:08:32 +00:00
|
|
|
import type { GetServerSideProps, NextPage } from "next";
|
|
|
|
import { getSession } from "next-auth/react";
|
2022-04-12 19:18:16 +00:00
|
|
|
import { dehydrate, QueryClient } from "react-query";
|
2022-04-03 20:04:28 +00:00
|
|
|
import { CustomHead } from "../components/CustomHead";
|
2022-04-04 02:52:03 +00:00
|
|
|
import { Layout } from "../components/Layout";
|
2022-04-14 20:34:38 +00:00
|
|
|
import VideoList from "../components/VideoList/";
|
2022-04-07 22:54:15 +00:00
|
|
|
import { getVideos } from "../lib/getVideos";
|
|
|
|
|
2022-04-14 20:34:38 +00:00
|
|
|
const Home: NextPage = () => {
|
2022-03-29 17:19:24 +00:00
|
|
|
return (
|
|
|
|
<>
|
2022-04-03 20:04:28 +00:00
|
|
|
<CustomHead />
|
2022-03-29 17:19:24 +00:00
|
|
|
|
2022-04-04 02:52:03 +00:00
|
|
|
<Layout>
|
2022-04-12 19:18:16 +00:00
|
|
|
<VideoList />
|
2022-04-04 02:52:03 +00:00
|
|
|
</Layout>
|
2022-03-29 17:19:24 +00:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Home;
|
2022-04-04 02:52:03 +00:00
|
|
|
|
2022-04-13 18:08:32 +00:00
|
|
|
export const getServerSideProps: GetServerSideProps = async (context) => {
|
2022-04-12 19:18:16 +00:00
|
|
|
const queryClient = new QueryClient();
|
2022-04-13 18:08:32 +00:00
|
|
|
const session = await getSession(context);
|
|
|
|
|
|
|
|
if (!session) {
|
|
|
|
return {
|
|
|
|
redirect: {
|
|
|
|
destination: "/auth/login",
|
|
|
|
permanent: false,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
2022-04-12 19:18:16 +00:00
|
|
|
|
2022-04-13 20:53:39 +00:00
|
|
|
await queryClient.prefetchQuery(["videos", session.ta_token.token], () =>
|
2022-04-13 18:08:32 +00:00
|
|
|
getVideos(session.ta_token.token)
|
|
|
|
);
|
2022-04-12 19:18:16 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
props: {
|
|
|
|
dehydratedState: dehydrate(queryClient),
|
2022-04-13 20:53:39 +00:00
|
|
|
session,
|
2022-04-12 19:18:16 +00:00
|
|
|
},
|
|
|
|
};
|
2022-04-04 02:52:03 +00:00
|
|
|
};
|