2021-09-21 09:29:20 +00:00
|
|
|
import React from "react";
|
2021-09-22 19:52:38 +00:00
|
|
|
|
2021-10-02 16:53:13 +00:00
|
|
|
import { getSession } from "@lib/auth";
|
2021-09-21 09:29:20 +00:00
|
|
|
import prisma from "@lib/prisma";
|
2021-09-22 19:52:38 +00:00
|
|
|
|
2021-09-29 21:33:18 +00:00
|
|
|
import SettingsShell from "@components/SettingsShell";
|
2021-09-22 19:52:38 +00:00
|
|
|
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 }) {
|
|
|
|
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);
|
2021-10-02 16:53:13 +00:00
|
|
|
if (!session?.user?.id) {
|
2021-09-21 09:29:20 +00:00
|
|
|
return { redirect: { permanent: false, destination: "/auth/login" } };
|
|
|
|
}
|
|
|
|
|
|
|
|
const user = await prisma.user.findFirst({
|
|
|
|
where: {
|
2021-10-02 16:53:13 +00:00
|
|
|
id: session.user.id,
|
2021-09-21 09:29:20 +00:00
|
|
|
},
|
|
|
|
select: {
|
|
|
|
id: true,
|
|
|
|
username: true,
|
|
|
|
name: true,
|
|
|
|
twoFactorEnabled: true,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
return {
|
2021-09-24 10:16:46 +00:00
|
|
|
props: { session, user },
|
2021-09-21 09:29:20 +00:00
|
|
|
};
|
|
|
|
}
|