Started on simple admin page
continuous-integration/drone/push Build is failing Details

main
Guus van Meerveld 2 years ago
parent 62ac743f79
commit 1240be41cd
Signed by: Guusvanmeerveld
GPG Key ID: 2BA7D7912771966E

@ -1,4 +1,3 @@
NEXT_PUBLIC_GITEA_USERNAME=Guusvanmeerveld NEXT_PUBLIC_GITEA_USERNAME=Guusvanmeerveld
NEXT_PUBLIC_GITEA_SERVER=git.guusvanmeerveld.dev NEXT_PUBLIC_GITEA_SERVER=git.guusvanmeerveld.dev
DATABASE_URL=postgresql://portfolio:portfolio@localhost:5432/portfolio?schema=public 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;

@ -13,6 +13,7 @@ datasource db {
model User { model User {
id Int @id @default(autoincrement()) id Int @id @default(autoincrement())
email String @unique email String @unique
admin Boolean @default(false)
password String password String
name String name String
posts Post[] posts Post[]

@ -45,7 +45,8 @@ const handle: NextApiHandler = async (req, res) => {
data: { data: {
email: signupCredentials.data.email, email: signupCredentials.data.email,
name: signupCredentials.data.name, name: signupCredentials.data.name,
password password,
admin: process.env.ADMIN_EMAIL === signupCredentials.data.email
} }
}) })
.then(async (user) => { .then(async (user) => {

@ -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;

@ -25,6 +25,7 @@ export const getStaticProps: GetStaticProps = async () => {
repositories.reduce((prev, current) => repositories.reduce((prev, current) =>
prev.stars_count > current.stars_count ? prev : current prev.stars_count > current.stars_count ? prev : current
); );
return { return {
props: { props: {
isAvailable, isAvailable,

Loading…
Cancel
Save