Use id to look up user (#843)
This commit is contained in:
parent
eb93e778bd
commit
33273b18d3
1 changed files with 3 additions and 11 deletions
|
@ -1,22 +1,14 @@
|
||||||
import { getSession, useSession } from "next-auth/client";
|
|
||||||
import React from "react";
|
import React from "react";
|
||||||
|
|
||||||
|
import { getSession } from "@lib/auth";
|
||||||
import prisma from "@lib/prisma";
|
import prisma from "@lib/prisma";
|
||||||
|
|
||||||
import Loader from "@components/Loader";
|
|
||||||
import SettingsShell from "@components/SettingsShell";
|
import SettingsShell from "@components/SettingsShell";
|
||||||
import Shell from "@components/Shell";
|
import Shell from "@components/Shell";
|
||||||
import ChangePasswordSection from "@components/security/ChangePasswordSection";
|
import ChangePasswordSection from "@components/security/ChangePasswordSection";
|
||||||
import TwoFactorAuthSection from "@components/security/TwoFactorAuthSection";
|
import TwoFactorAuthSection from "@components/security/TwoFactorAuthSection";
|
||||||
|
|
||||||
export default function Security({ user }) {
|
export default function Security({ user }) {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
||||||
const [session, loading] = useSession();
|
|
||||||
|
|
||||||
if (loading) {
|
|
||||||
return <Loader />;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Shell heading="Security" subtitle="Manage your account's security.">
|
<Shell heading="Security" subtitle="Manage your account's security.">
|
||||||
<SettingsShell>
|
<SettingsShell>
|
||||||
|
@ -29,13 +21,13 @@ export default function Security({ user }) {
|
||||||
|
|
||||||
export async function getServerSideProps(context) {
|
export async function getServerSideProps(context) {
|
||||||
const session = await getSession(context);
|
const session = await getSession(context);
|
||||||
if (!session) {
|
if (!session?.user?.id) {
|
||||||
return { redirect: { permanent: false, destination: "/auth/login" } };
|
return { redirect: { permanent: false, destination: "/auth/login" } };
|
||||||
}
|
}
|
||||||
|
|
||||||
const user = await prisma.user.findFirst({
|
const user = await prisma.user.findFirst({
|
||||||
where: {
|
where: {
|
||||||
email: session.user.email,
|
id: session.user.id,
|
||||||
},
|
},
|
||||||
select: {
|
select: {
|
||||||
id: true,
|
id: true,
|
||||||
|
|
Loading…
Reference in a new issue