mirror of https://github.com/MaxLeiter/Drift
fix admin page, expiring view, displayName setting/field
parent
0627ab7396
commit
2b783145d4
@ -1,18 +0,0 @@
|
||||
import { getCurrentUser } from "@lib/server/session"
|
||||
import Admin from "./components/admin"
|
||||
import { notFound } from "next/navigation"
|
||||
|
||||
const AdminPage = async () => {
|
||||
const user = await getCurrentUser();
|
||||
if (!user) {
|
||||
return notFound()
|
||||
}
|
||||
|
||||
if (user.role !== "admin") {
|
||||
return notFound()
|
||||
}
|
||||
|
||||
return <Admin />
|
||||
}
|
||||
|
||||
export default AdminPage
|
||||
@ -1,100 +0,0 @@
|
||||
/* latin */
|
||||
@font-face {
|
||||
font-family: "Inter";
|
||||
font-style: normal;
|
||||
font-weight: 100;
|
||||
font-display: block;
|
||||
src: url(https://assets.vercel.com/raw/upload/v1587415301/fonts/2/inter-var-latin.woff2)
|
||||
format("woff2");
|
||||
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
|
||||
U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215,
|
||||
U+FEFF, U+FFFD;
|
||||
}
|
||||
@font-face {
|
||||
font-family: "Inter";
|
||||
font-style: normal;
|
||||
font-weight: 200;
|
||||
font-display: block;
|
||||
src: url(https://assets.vercel.com/raw/upload/v1587415301/fonts/2/inter-var-latin.woff2)
|
||||
format("woff2");
|
||||
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
|
||||
U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215,
|
||||
U+FEFF, U+FFFD;
|
||||
}
|
||||
@font-face {
|
||||
font-family: "Inter";
|
||||
font-style: normal;
|
||||
font-weight: 300;
|
||||
font-display: block;
|
||||
src: url(https://assets.vercel.com/raw/upload/v1587415301/fonts/2/inter-var-latin.woff2)
|
||||
format("woff2");
|
||||
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
|
||||
U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215,
|
||||
U+FEFF, U+FFFD;
|
||||
}
|
||||
@font-face {
|
||||
font-family: "Inter";
|
||||
font-style: normal;
|
||||
font-weight: 400;
|
||||
font-display: block;
|
||||
src: url(https://assets.vercel.com/raw/upload/v1587415301/fonts/2/inter-var-latin.woff2)
|
||||
format("woff2");
|
||||
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
|
||||
U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215,
|
||||
U+FEFF, U+FFFD;
|
||||
}
|
||||
@font-face {
|
||||
font-family: "Inter";
|
||||
font-style: normal;
|
||||
font-weight: 500;
|
||||
font-display: block;
|
||||
src: url(https://assets.vercel.com/raw/upload/v1587415301/fonts/2/inter-var-latin.woff2)
|
||||
format("woff2");
|
||||
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
|
||||
U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215,
|
||||
U+FEFF, U+FFFD;
|
||||
}
|
||||
@font-face {
|
||||
font-family: "Inter";
|
||||
font-style: normal;
|
||||
font-weight: 600;
|
||||
font-display: block;
|
||||
src: url(https://assets.vercel.com/raw/upload/v1587415301/fonts/2/inter-var-latin.woff2)
|
||||
format("woff2");
|
||||
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
|
||||
U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215,
|
||||
U+FEFF, U+FFFD;
|
||||
}
|
||||
@font-face {
|
||||
font-family: "Inter";
|
||||
font-style: normal;
|
||||
font-weight: 700;
|
||||
font-display: block;
|
||||
src: url(https://assets.vercel.com/raw/upload/v1587415301/fonts/2/inter-var-latin.woff2)
|
||||
format("woff2");
|
||||
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
|
||||
U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215,
|
||||
U+FEFF, U+FFFD;
|
||||
}
|
||||
@font-face {
|
||||
font-family: "Inter";
|
||||
font-style: normal;
|
||||
font-weight: 800;
|
||||
font-display: block;
|
||||
src: url(https://assets.vercel.com/raw/upload/v1587415301/fonts/2/inter-var-latin.woff2)
|
||||
format("woff2");
|
||||
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
|
||||
U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215,
|
||||
U+FEFF, U+FFFD;
|
||||
}
|
||||
@font-face {
|
||||
font-family: "Inter";
|
||||
font-style: normal;
|
||||
font-weight: 900;
|
||||
font-display: block;
|
||||
src: url(https://assets.vercel.com/raw/upload/v1587415301/fonts/2/inter-var-latin.woff2)
|
||||
format("woff2");
|
||||
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
|
||||
U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215,
|
||||
U+FEFF, U+FFFD;
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
|
||||
module.exports = {
|
||||
preset: "ts-jest",
|
||||
testEnvironment: "node",
|
||||
setupFiles: ["<rootDir>/test/setup-tests.ts"],
|
||||
moduleNameMapper: {
|
||||
"@lib/(.*)": "<rootDir>/src/lib/$1",
|
||||
"@routes/(.*)": "<rootDir>/src/routes/$1"
|
||||
},
|
||||
testPathIgnorePatterns: ["<rootDir>/node_modules/", "<rootDir>/dist/"]
|
||||
}
|
||||
@ -1,40 +0,0 @@
|
||||
export type PostVisibility = "unlisted" | "private" | "public" | "protected"
|
||||
|
||||
export type Document = {
|
||||
title: string
|
||||
content: string
|
||||
id: string
|
||||
}
|
||||
|
||||
export type File = {
|
||||
id: string
|
||||
title: string
|
||||
content: string
|
||||
html: string
|
||||
createdAt: string
|
||||
}
|
||||
|
||||
type Files = File[]
|
||||
|
||||
export type Post = {
|
||||
id: string
|
||||
title: string
|
||||
description: string
|
||||
visibility: PostVisibility
|
||||
files?: Files
|
||||
createdAt: string
|
||||
users?: User[]
|
||||
parent?: Pick<Post, "id" | "title" | "visibility" | "createdAt">
|
||||
expiresAt: Date | string | null
|
||||
}
|
||||
|
||||
type User = {
|
||||
id: string
|
||||
username: string
|
||||
posts?: Post[]
|
||||
role: "admin" | "user" | ""
|
||||
createdAt: string
|
||||
displayName?: string
|
||||
bio?: string
|
||||
email?: string
|
||||
}
|
||||
@ -0,0 +1,52 @@
|
||||
// api/user/[id].ts
|
||||
|
||||
import { parseQueryParam } from "@lib/server/parse-query-param"
|
||||
import { getUserById } from "@lib/server/prisma"
|
||||
import { NextApiRequest, NextApiResponse } from "next"
|
||||
import { prisma } from "lib/server/prisma"
|
||||
import { withMethods } from "@lib/api-middleware/with-methods"
|
||||
import { getSession } from "next-auth/react"
|
||||
|
||||
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
const id = parseQueryParam(req.query.id)
|
||||
if (!id) {
|
||||
return res.status(400).json({ error: "Missing id" })
|
||||
}
|
||||
|
||||
const user = await getUserById(id)
|
||||
const currUser = (await getSession({ req }))?.user
|
||||
|
||||
if (!user) {
|
||||
return res.status(404).json({ message: "User not found" })
|
||||
}
|
||||
|
||||
if (user.id !== currUser?.id) {
|
||||
return res.status(403).json({ message: "Unauthorized" })
|
||||
}
|
||||
|
||||
switch (req.method) {
|
||||
case "PUT":
|
||||
const { displayName } = req.body
|
||||
const updatedUser = await prisma.user.update({
|
||||
where: {
|
||||
id
|
||||
},
|
||||
data: {
|
||||
displayName
|
||||
// bio
|
||||
}
|
||||
})
|
||||
|
||||
return res.json({
|
||||
id: updatedUser.id,
|
||||
name: updatedUser.displayName
|
||||
// bio: updatedUser.bio
|
||||
})
|
||||
case "GET":
|
||||
return res.json(currUser)
|
||||
default:
|
||||
return res.status(405).json({ message: "Method not allowed" })
|
||||
}
|
||||
}
|
||||
|
||||
export default withMethods(["GET", "PUT"], handler)
|
||||
@ -1,24 +0,0 @@
|
||||
import { getCurrentUser } from "@lib/server/session"
|
||||
import { NextApiRequest, NextApiResponse } from "next"
|
||||
|
||||
|
||||
export default async function handler(
|
||||
_: NextApiRequest,
|
||||
res: NextApiResponse
|
||||
): Promise<any> {
|
||||
const error = () =>
|
||||
res.status(401).json({
|
||||
message: "Unauthorized"
|
||||
})
|
||||
try {
|
||||
const user = await getCurrentUser()
|
||||
|
||||
if (!user) {
|
||||
return error()
|
||||
}
|
||||
return res.json(user)
|
||||
} catch (e) {
|
||||
console.warn(`/api/user/self:`, e)
|
||||
return error()
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue