cal.pub0.org/pages/settings/security.tsx

44 lines
1.1 KiB
TypeScript
Raw Normal View History

import React from "react";
2021-10-02 16:53:13 +00:00
import { getSession } from "@lib/auth";
import prisma from "@lib/prisma";
import SettingsShell from "@components/SettingsShell";
import Shell from "@components/Shell";
import ChangePasswordSection from "@components/security/ChangePasswordSection";
import TwoFactorAuthSection from "@components/security/TwoFactorAuthSection";
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) {
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,
},
select: {
id: true,
username: true,
name: true,
twoFactorEnabled: true,
},
});
return {
props: { session, user },
};
}