2021-09-22 19:52:38 +00:00
|
|
|
import { getSession, useSession } from "next-auth/client";
|
2021-09-21 09:29:20 +00:00
|
|
|
import React from "react";
|
2021-09-22 19:52:38 +00:00
|
|
|
|
2021-09-21 09:29:20 +00:00
|
|
|
import prisma from "@lib/prisma";
|
2021-09-22 19:52:38 +00:00
|
|
|
|
2021-09-21 09:29:20 +00:00
|
|
|
import Loader from "@components/Loader";
|
2021-09-22 19:52:38 +00:00
|
|
|
import SettingsShell from "@components/Settings";
|
|
|
|
import Shell from "@components/Shell";
|
2021-09-21 09:29:20 +00:00
|
|
|
import ChangePasswordSection from "@components/security/ChangePasswordSection";
|
2021-09-22 19:52:38 +00:00
|
|
|
import TwoFactorAuthSection from "@components/security/TwoFactorAuthSection";
|
2021-09-21 09:29:20 +00:00
|
|
|
|
|
|
|
export default function Security({ user }) {
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
|
|
const [session, loading] = useSession();
|
|
|
|
|
|
|
|
if (loading) {
|
|
|
|
return <Loader />;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Shell heading="Security" subtitle="Manage your account's security.">
|
|
|
|
<SettingsShell>
|
|
|
|
<ChangePasswordSection />
|
|
|
|
<TwoFactorAuthSection twoFactorEnabled={user.twoFactorEnabled} />
|
|
|
|
</SettingsShell>
|
|
|
|
</Shell>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function getServerSideProps(context) {
|
|
|
|
const session = await getSession(context);
|
|
|
|
if (!session) {
|
|
|
|
return { redirect: { permanent: false, destination: "/auth/login" } };
|
|
|
|
}
|
|
|
|
|
|
|
|
const user = await prisma.user.findFirst({
|
|
|
|
where: {
|
|
|
|
email: session.user.email,
|
|
|
|
},
|
|
|
|
select: {
|
|
|
|
id: true,
|
|
|
|
username: true,
|
|
|
|
name: true,
|
|
|
|
twoFactorEnabled: true,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
return {
|
|
|
|
props: { user }, // will be passed to the page component as props
|
|
|
|
};
|
|
|
|
}
|