many breaking changes/fixes

This commit is contained in:
Daniel
2023-03-28 11:01:50 +03:30
parent 3a5ae28f86
commit b9567ca3c2
43 changed files with 1180 additions and 466 deletions
+23
View File
@@ -3,10 +3,33 @@ import MainLayout from "@/layouts/MainLayout";
import "@/styles/globals.css";
import { SessionProvider } from "next-auth/react";
import type { AppProps } from "next/app";
import Head from "next/head";
export default function App({ Component, pageProps }: AppProps) {
return (
<SessionProvider session={pageProps.session}>
<Head>
<title>Linkwarden</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link
rel="apple-touch-icon"
sizes="180x180"
href="/apple-touch-icon.png"
/>
<link
rel="icon"
type="image/png"
sizes="32x32"
href="/favicon-32x32.png"
/>
<link
rel="icon"
type="image/png"
sizes="16x16"
href="/favicon-16x16.png"
/>
<link rel="manifest" href="/site.webmanifest" />
</Head>
<MainLayout>
<Component {...pageProps} />
</MainLayout>
+2
View File
@@ -35,6 +35,8 @@ export const authOptions: AuthOptions = {
passwordMatches = bcrypt.compareSync(password, findUser.password);
}
console.log(passwordMatches);
if (passwordMatches) {
return {
id: findUser?.id,
+15 -11
View File
@@ -4,21 +4,25 @@ import { authOptions } from "pages/api/auth/[...nextauth]";
import getCollections from "@/lib/api/controllers/collections/getCollections";
import postCollection from "@/lib/api/controllers/collections/postCollection";
type Data = {
response: object[] | string;
};
export default async function (
req: NextApiRequest,
res: NextApiResponse<Data>
) {
export default async function (req: NextApiRequest, res: NextApiResponse) {
const session = await getServerSession(req, res, authOptions);
if (!session?.user?.email) {
return res.status(401).json({ response: "You must be logged in." });
}
if (req.method === "GET") return await getCollections(req, res, session);
if (req.method === "POST") return await postCollection(req, res, session);
if (req.method === "GET") {
const collections = await getCollections(session.user.id);
return res
.status(collections.status)
.json({ response: collections.response });
} else if (req.method === "POST") {
const newCollection = await postCollection(
req.body.collectionName.trim(),
session.user.id
);
return res
.status(newCollection.status)
.json({ response: newCollection.response });
}
}
+15 -11
View File
@@ -5,21 +5,25 @@ import getLinks from "@/lib/api/controllers/links/getLinks";
import postLink from "@/lib/api/controllers/links/postLink";
import deleteLink from "@/lib/api/controllers/links/deleteLink";
type Data = {
response: object[] | string;
};
export default async function (
req: NextApiRequest,
res: NextApiResponse<Data>
) {
export default async function (req: NextApiRequest, res: NextApiResponse) {
const session = await getServerSession(req, res, authOptions);
if (!session?.user?.email) {
return res.status(401).json({ response: "You must be logged in." });
}
if (req.method === "GET") return await getLinks(req, res, session);
else if (req.method === "POST") return await postLink(req, res, session);
else if (req.method === "DELETE") return await deleteLink(req, res, session);
if (req.method === "GET") {
const links = await getLinks(session.user.id);
return res.status(links.status).json({ response: links.response });
} else if (req.method === "POST") {
const newlink = await postLink(req.body, session.user.id);
return res.status(newlink.status).json({
response: newlink.response,
});
} else if (req.method === "DELETE") {
const deleted = await deleteLink(req.body, session.user.id);
return res.status(deleted.status).json({
response: deleted.response,
});
}
}
+4 -1
View File
@@ -17,5 +17,8 @@ export default async function (
return res.status(401).json({ response: "You must be logged in." });
}
if (req.method === "GET") return await getTags(req, res, session);
if (req.method === "GET") {
const tags = await getTags(session.user.id);
return res.status(tags.status).json({ response: tags.response });
}
}
+1 -4
View File
@@ -12,10 +12,7 @@ export default function () {
return (
// ml-80
<div className="p-2">
<p className="text-right mb-2 text-gray-500 font-bold text-sm">
{linksByCollection.length || 0} Links Found
</p>
<div className="p-5 flex flex-col gap-5 w-full">
{linksByCollection.map((e, i) => {
return <LinkList key={i} link={e} count={i} />;
})}
+45 -9
View File
@@ -1,20 +1,56 @@
import { useSession } from "next-auth/react";
import useCollectionStore from "@/store/collections";
import { faAdd, faBox, faEllipsis } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import CollectionCard from "@/components/CollectionCard";
import Dropdown from "@/components/Dropdown";
import { useState } from "react";
export default function () {
const { collections } = useCollectionStore();
const { data: session, status } = useSession();
const user = session?.user;
const [editDropdown, setEditDropdown] = useState(false);
return (
// ml-80
<div className="flex flex-wrap p-2 gap-2">
{collections.map((e, i) => {
return <CollectionCard key={i} collection={e} />;
})}
<div className="p-5">
<div className="flex gap-3 items-center mb-5">
<div className="flex gap-2 items-center">
<FontAwesomeIcon icon={faBox} className="w-5 h-5 text-sky-300" />
<p className="text-lg text-sky-900">All Collections</p>
</div>
<div className="relative">
<div
onClick={() => setEditDropdown(!editDropdown)}
id="edit-dropdown"
className="inline-flex rounded-md cursor-pointer hover:bg-white hover:border-sky-500 border-sky-100 border duration-100 p-1"
>
<FontAwesomeIcon
icon={faEllipsis}
id="edit-dropdown"
className="w-4 h-4 text-gray-500"
/>
</div>
{editDropdown ? (
<Dropdown
items={[
{
name: "New",
icon: <FontAwesomeIcon icon={faAdd} />,
},
]}
onClickOutside={(e: Event) => {
const target = e.target as HTMLInputElement;
if (target.id !== "edit-dropdown") setEditDropdown(false);
}}
className="absolute top-7 left-0"
/>
) : null}
</div>
</div>
<div className="flex flex-wrap gap-5">
{collections.map((e, i) => {
return <CollectionCard key={i} collection={e} />;
})}
</div>
</div>
);
}
+14
View File
@@ -0,0 +1,14 @@
import LinkList from "@/components/LinkList";
import useLinkStore from "@/store/links";
export default function Links() {
const { links } = useLinkStore();
return (
<div className="p-5 flex flex-col gap-5 w-full">
{links.map((e, i) => {
return <LinkList key={i} link={e} count={i} />;
})}
</div>
);
}
+2
View File
@@ -21,6 +21,8 @@ export default function () {
password: form.password,
});
console.log(res?.status);
if (res?.ok) {
setForm({
email: "",