added settings modal UI
This commit is contained in:
@@ -5,21 +5,28 @@
|
||||
|
||||
import { prisma } from "@/lib/api/db";
|
||||
|
||||
export default async function (email: string) {
|
||||
export default async function (lookupEmail: string, isSelf: boolean) {
|
||||
const user = await prisma.user.findUnique({
|
||||
where: {
|
||||
email,
|
||||
email: lookupEmail,
|
||||
},
|
||||
});
|
||||
|
||||
const unsensitiveUserInfo = {
|
||||
id: user?.id,
|
||||
name: user?.name,
|
||||
email: user?.email,
|
||||
createdAt: user?.createdAt,
|
||||
};
|
||||
const data = isSelf
|
||||
? {
|
||||
// If user is requesting its data
|
||||
id: user?.id,
|
||||
name: user?.name,
|
||||
email: user?.email,
|
||||
}
|
||||
: {
|
||||
// If user is requesting someone elses data
|
||||
id: user?.id,
|
||||
name: user?.name,
|
||||
email: user?.email,
|
||||
};
|
||||
|
||||
const statusCode = user?.id ? 200 : 404;
|
||||
|
||||
return { response: unsensitiveUserInfo || null, status: statusCode };
|
||||
return { response: data || null, status: statusCode };
|
||||
}
|
||||
|
||||
@@ -8,18 +8,21 @@ import { useEffect } from "react";
|
||||
import { useSession } from "next-auth/react";
|
||||
import useTagStore from "@/store/tags";
|
||||
import useLinkStore from "@/store/links";
|
||||
import useAccountStore from "@/store/account";
|
||||
|
||||
export default function () {
|
||||
const { status } = useSession();
|
||||
const { status, data } = useSession();
|
||||
const { setCollections } = useCollectionStore();
|
||||
const { setTags } = useTagStore();
|
||||
const { setLinks } = useLinkStore();
|
||||
const { setAccount } = useAccountStore();
|
||||
|
||||
useEffect(() => {
|
||||
if (status === "authenticated") {
|
||||
setCollections();
|
||||
setTags();
|
||||
setLinks();
|
||||
setAccount(data.user.email as string);
|
||||
}
|
||||
}, [status]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user