From d260c9b341f2ed22d865240939b3acac30db868f Mon Sep 17 00:00:00 2001 From: MarconLP <13001502+MarconLP@users.noreply.github.com> Date: Thu, 20 Apr 2023 00:39:03 +0200 Subject: [PATCH] redirect logged-in users from / to /videos --- src/pages/index.tsx | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/pages/index.tsx b/src/pages/index.tsx index d359735..6fb3db3 100644 --- a/src/pages/index.tsx +++ b/src/pages/index.tsx @@ -1,9 +1,8 @@ -import { type NextPage } from "next"; +import { GetServerSideProps, type NextPage } from "next"; import Head from "next/head"; -import { signIn, signOut, useSession } from "next-auth/react"; +import { getSession } from "next-auth/react"; import { Bars3Icon, XMarkIcon } from "@heroicons/react/24/outline"; -import { api } from "~/utils/api"; import { Dialog } from "@headlessui/react"; import { useState } from "react"; import Link from "next/link"; @@ -188,4 +187,21 @@ const Home: NextPage = () => { ); }; -export default Home; \ No newline at end of file +export default Home; + +export const getServerSideProps: GetServerSideProps = async (context) => { + const session = await getSession(context); + + if (session) { + return { + redirect: { + destination: "/videos", + permanent: false, + }, + }; + } + + return { + props: { session }, + }; +};