Skip to content

Commit 1548964

Browse files
committed
chore: add build artifacts and git objects to version control
1 parent 6234df7 commit 1548964

9 files changed

Lines changed: 36 additions & 18 deletions

File tree

app/[locale]/admin/config/page.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Typography from "@mui/material/Typography";
22
import Box from "@mui/material/Box";
33
import { getTranslations, setRequestLocale } from "next-intl/server";
4-
import { getD1, getDb } from "@/lib/db";
4+
import { getAdminDb } from "@/lib/auth-helpers";
55
import { tags, platforms } from "@/db/schema";
66
import ConfigClient from "./ConfigClient";
77

@@ -10,8 +10,7 @@ export default async function AdminConfigPage({ params }: { params: Promise<{ lo
1010
setRequestLocale(locale);
1111
const tAdmin = await getTranslations("Admin.config");
1212

13-
const d1 = await getD1();
14-
const db = getDb(d1);
13+
const { db } = await getAdminDb();
1514

1615
const [allTags, allPlatforms] = await Promise.all([
1716
db.select().from(tags).all(),

app/[locale]/admin/ideas/page.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getDatabase } from "@/lib/db";
1+
import { getAdminDb } from "@/lib/auth-helpers";
22
import { ideas, users, userProfiles } from "@/db/schema";
33
import { desc, eq } from "drizzle-orm";
44
import Typography from "@mui/material/Typography";
@@ -10,7 +10,7 @@ export default async function AdminIdeasPage({ params }: { params: Promise<{ loc
1010
setRequestLocale(locale);
1111
const tAdmin = await getTranslations("Admin.ideas");
1212

13-
const db = await getDatabase();
13+
const { db } = await getAdminDb();
1414
const allIdeas = await db
1515
.select({
1616
id: ideas.id,

app/[locale]/admin/page.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import CardContent from "@mui/material/CardContent";
66
import Stack from "@mui/material/Stack";
77
import Box from "@mui/material/Box";
88
import Button from "@mui/material/Button";
9-
import { auth } from "@/lib/auth";
9+
import { getAdminDb } from "@/lib/auth-helpers";
1010
import { redirect } from "next/navigation";
1111
import { setRequestLocale, getTranslations } from "next-intl/server";
1212
import { Link } from "@/i18n/routing";
@@ -22,8 +22,11 @@ export default async function AdminDashboardPage({ params }: AdminDashboardProps
2222
const { locale } = await params;
2323
setRequestLocale(locale);
2424

25-
const session = await auth();
26-
if (session?.user?.role !== "admin") redirect("/");
25+
try {
26+
await getAdminDb();
27+
} catch (e) {
28+
redirect("/");
29+
}
2730

2831
const tAdmin = await getTranslations("Admin");
2932

app/[locale]/admin/projects/page.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getDatabase } from "@/lib/db";
1+
import { getAdminDb } from "@/lib/auth-helpers";
22
import { projects, users, userProfiles } from "@/db/schema";
33
import { desc, eq } from "drizzle-orm";
44
import Typography from "@mui/material/Typography";
@@ -10,7 +10,7 @@ export default async function AdminProjectsPage({ params }: { params: Promise<{
1010
setRequestLocale(locale);
1111
const tAdmin = await getTranslations("Admin.projects");
1212

13-
const db = await getDatabase();
13+
const { db } = await getAdminDb();
1414
const allProjects = await db
1515
.select({
1616
id: projects.id,

app/[locale]/admin/reports/page.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import Chip from "@mui/material/Chip";
77
import Button from "@mui/material/Button";
88
import Stack from "@mui/material/Stack";
99
import Divider from "@mui/material/Divider";
10-
import { auth } from "@/lib/auth";
10+
import { getAdminDb } from "@/lib/auth-helpers";
1111
import { redirect } from "next/navigation";
1212
import { setRequestLocale, getTranslations } from "next-intl/server";
1313
import { Link } from "@/i18n/routing";
@@ -21,8 +21,11 @@ export default async function AdminReportsPage({ params }: AdminReportsPageProps
2121
const { locale } = await params;
2222
setRequestLocale(locale);
2323

24-
const session = await auth();
25-
if (session?.user?.role !== "admin") redirect("/");
24+
try {
25+
await getAdminDb();
26+
} catch (e) {
27+
redirect("/");
28+
}
2629

2730
const tAdmin = await getTranslations("Admin");
2831
const reports = await getReports();

app/[locale]/admin/users/page.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getDatabase } from "@/lib/db";
1+
import { getAdminDb } from "@/lib/auth-helpers";
22
import { users, userProfiles } from "@/db/schema";
33
import { desc, eq } from "drizzle-orm";
44
import Typography from "@mui/material/Typography";
@@ -10,7 +10,7 @@ export default async function AdminUsersPage({ params }: { params: Promise<{ loc
1010
setRequestLocale(locale);
1111
const tAdmin = await getTranslations("Admin.users");
1212

13-
const db = await getDatabase();
13+
const { db } = await getAdminDb();
1414
const { isNull } = await import("drizzle-orm");
1515
const allUsers = await db.select({
1616
id: users.id,

lib/actions/auth.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,8 @@ export async function resetPasswordWithToken(formData: FormData) {
215215
const newPassword = formData.get("password") as string;
216216

217217
if (!token || !newPassword) return { error: "invalidData" };
218+
219+
if (newPassword.length < 8) return { error: "passwordLength" };
218220

219221
const { checkRateLimit } = await import("@/lib/rate-limit");
220222
const rlRes = await checkRateLimit("reset_password_confirm", 5, 15 * 60 * 1000);

lib/actions/favorite.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ export async function toggleCookieFavorite(projectId: string) {
100100
if (favorites.includes(projectId)) {
101101
favorites = favorites.filter(id => id !== projectId);
102102
} else {
103+
// M-4: Limit max cookie favorites to 50 to prevent DoS via huge cookie size
104+
if (favorites.length >= 50) {
105+
favorites.shift(); // Remove the oldest favorite
106+
}
103107
favorites.push(projectId);
104108
favorited = true;
105109
}

lib/auth-helpers.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,18 @@ export async function getAdminDb() {
3030
* 権限がない場合は "Forbidden" エラーをスローします。
3131
*/
3232
export async function assertProjectAccess(db: any, project: { id: string; authorId: string }, session: any) {
33-
if (project.authorId === session.user.id || session.user.role === "admin") {
34-
return true; // Author or Admin
33+
if (project.authorId === session.user.id) {
34+
return true; // Author
3535
}
36-
const { projectMembers } = await import("@/db/schema");
36+
37+
const { users, projectMembers } = await import("@/db/schema");
3738
const { eq, and } = await import("drizzle-orm");
39+
40+
const dbUser = await db.select({ role: users.role }).from(users).where(eq(users.id, session.user.id)).get();
41+
if (dbUser?.role === "admin") {
42+
return true; // Admin
43+
}
44+
3845
const member = await db.select()
3946
.from(projectMembers)
4047
.where(and(eq(projectMembers.projectId, project.id), eq(projectMembers.userId, session.user.id)))

0 commit comments

Comments
 (0)