Started on simple admin page
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
parent
62ac743f79
commit
1240be41cd
@ -1,4 +1,3 @@
|
||||
NEXT_PUBLIC_GITEA_USERNAME=Guusvanmeerveld
|
||||
NEXT_PUBLIC_GITEA_SERVER=git.guusvanmeerveld.dev
|
||||
DATABASE_URL=postgresql://portfolio:portfolio@localhost:5432/portfolio?schema=public
|
||||
# NEXT_PUBLIC_ALLOW_REGISTRATION=true
|
@ -0,0 +1,9 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- Made the column `name` on table `User` required. This step will fail if there are existing NULL values in that column.
|
||||
|
||||
*/
|
||||
-- AlterTable
|
||||
ALTER TABLE "User" ADD COLUMN "admin" BOOLEAN NOT NULL DEFAULT false,
|
||||
ALTER COLUMN "name" SET NOT NULL;
|
@ -0,0 +1,35 @@
|
||||
import { NextPage } from "next";
|
||||
import { NextSeo } from "next-seo";
|
||||
|
||||
import { Post, User } from "@prisma/client";
|
||||
|
||||
import Layout from "@components/Layout";
|
||||
import { withSessionSsr } from "@utils/session";
|
||||
|
||||
const AdminPage: NextPage<{ user: User; posts: Post & { author: User } }> = ({
|
||||
user,
|
||||
posts
|
||||
}) => {
|
||||
return (
|
||||
<Layout>
|
||||
<NextSeo title="Admin" />
|
||||
Welcome {user.name}
|
||||
</Layout>
|
||||
);
|
||||
};
|
||||
|
||||
export const getServerSideProps = withSessionSsr(async ({ req }) => {
|
||||
const user = req.session.user;
|
||||
|
||||
if (user === undefined || !user.admin) return { notFound: true };
|
||||
|
||||
const posts = await prisma.post.findMany({
|
||||
orderBy: { createdAt: "desc" },
|
||||
take: 5,
|
||||
include: { author: true }
|
||||
});
|
||||
|
||||
return { props: { user, posts } };
|
||||
});
|
||||
|
||||
export default AdminPage;
|
Loading…
Reference in new issue