21 lines
430 B
TypeScript
21 lines
430 B
TypeScript
import { GetServerSideProps, GetServerSidePropsContext } from "next";
|
|
import { getSession } from "next-auth/react";
|
|
|
|
export const checkAuth: GetServerSideProps = async (
|
|
context: GetServerSidePropsContext
|
|
) => {
|
|
const session = await getSession(context);
|
|
|
|
if (!session) {
|
|
return {
|
|
redirect: {
|
|
destination: "/login",
|
|
permanent: false,
|
|
},
|
|
};
|
|
}
|
|
|
|
return {
|
|
props: { session },
|
|
};
|
|
};
|