TikTok V5 + Security

This commit is contained in:
2026-07-11 22:09:10 +02:00
parent 671c1a1559
commit d542f849aa
36 changed files with 740 additions and 463 deletions

View File

@@ -2,7 +2,7 @@ import { NextRequest, NextResponse } from 'next/server';
import { getServerSession } from 'next-auth';
import { authOptions } from '@/lib/auth';
import { db } from '@/lib/db';
import { cookies } from 'next/headers';
import { getSessionUserId } from '@/lib/session';
export async function GET(
request: NextRequest,
@@ -16,9 +16,8 @@ export async function GET(
if (session?.user?.id) {
userId = session.user.id;
} else {
// Fallback: Check raw userId cookie (like /api/user does)
const cookieStore = await cookies();
userId = cookieStore.get('userId')?.value;
// Fallback: verified signed userId cookie (like /api/user does)
userId = getSessionUserId() ?? undefined;
}
if (!userId) {

View File

@@ -1,5 +1,5 @@
import { NextRequest, NextResponse } from 'next/server';
import { cookies } from 'next/headers';
import { getSessionUserId } from '@/lib/session';
import { db } from '@/lib/db';
import { z } from 'zod';
import { csrfProtection } from '@/lib/csrf';
@@ -18,7 +18,7 @@ export async function GET(
{ params }: { params: { id: string } }
) {
try {
const userId = cookies().get('userId')?.value;
const userId = getSessionUserId();
if (!userId) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
}
@@ -62,7 +62,7 @@ export async function PATCH(
return NextResponse.json({ error: csrfCheck.error }, { status: 403 });
}
const userId = cookies().get('userId')?.value;
const userId = getSessionUserId();
// Rate Limiting (user-based)
const clientId = userId || getClientIdentifier(request);
@@ -151,7 +151,7 @@ export async function DELETE(
return NextResponse.json({ error: csrfCheck.error }, { status: 403 });
}
const userId = cookies().get('userId')?.value;
const userId = getSessionUserId();
// Rate Limiting (user-based)
const clientId = userId || getClientIdentifier(request);