mirror of
https://github.com/tubearchivist/tubearchivist-frontend.git
synced 2024-11-17 09:30:11 +00:00
47 lines
1.0 KiB
TypeScript
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,
|
|
},
|
|
};
|
|
};
|