fix: await params in Next.js 16 routes and pages for TypeScript compatibility
This commit is contained in:
@@ -5,9 +5,10 @@ import { canAssignTournamentAdmin } from '@/lib/permissions';
|
||||
|
||||
export async function GET(
|
||||
request: NextRequest,
|
||||
{ params }: { params: { id: string } }
|
||||
{ params }: { params: Promise<{ id: string }> }
|
||||
) {
|
||||
try {
|
||||
const { id } = await params
|
||||
const session = await getSession();
|
||||
|
||||
if (!session) {
|
||||
@@ -25,12 +26,12 @@ export async function GET(
|
||||
return NextResponse.json({ error: 'Requesting user not found' }, { status: 404 });
|
||||
}
|
||||
|
||||
if (session.user.id !== params.id && requestingUser.role !== 'club_admin') {
|
||||
if (session.user.id !== id && requestingUser.role !== 'club_admin') {
|
||||
return NextResponse.json({ error: 'Forbidden' }, { status: 403 });
|
||||
}
|
||||
|
||||
const user = await prisma.user.findUnique({
|
||||
where: { id: params.id },
|
||||
where: { id },
|
||||
select: { role: true }
|
||||
});
|
||||
|
||||
@@ -46,9 +47,10 @@ export async function GET(
|
||||
|
||||
export async function PATCH(
|
||||
request: NextRequest,
|
||||
{ params }: { params: { id: string } }
|
||||
{ params }: { params: Promise<{ id: string }> }
|
||||
) {
|
||||
try {
|
||||
const { id } = await params
|
||||
// Check if the current user has permission to assign roles
|
||||
const permission = await canAssignTournamentAdmin();
|
||||
if (!permission.allowed) {
|
||||
|
||||
@@ -5,9 +5,10 @@ import { canEditUserProfiles } from '@/lib/permissions';
|
||||
|
||||
export async function GET(
|
||||
request: NextRequest,
|
||||
{ params }: { params: { id: string } }
|
||||
{ params }: { params: Promise<{ id: string }> }
|
||||
) {
|
||||
try {
|
||||
const { id } = await params
|
||||
const session = await getSession();
|
||||
|
||||
if (!session) {
|
||||
@@ -25,13 +26,13 @@ export async function GET(
|
||||
}
|
||||
|
||||
// Allow if requesting own profile or if user is club_admin
|
||||
const canView = session.user.id === params.id || requestingUser.role === 'club_admin';
|
||||
const canView = session.user.id === id || requestingUser.role === 'club_admin';
|
||||
if (!canView) {
|
||||
return NextResponse.json({ error: 'Forbidden' }, { status: 403 });
|
||||
}
|
||||
|
||||
const user = await prisma.user.findUnique({
|
||||
where: { id: params.id },
|
||||
where: { id },
|
||||
include: {
|
||||
player: true,
|
||||
}
|
||||
@@ -49,9 +50,10 @@ export async function GET(
|
||||
|
||||
export async function PATCH(
|
||||
request: NextRequest,
|
||||
{ params }: { params: { id: string } }
|
||||
{ params }: { params: Promise<{ id: string }> }
|
||||
) {
|
||||
try {
|
||||
const { id } = await params
|
||||
const session = await getSession();
|
||||
|
||||
if (!session) {
|
||||
|
||||
Reference in New Issue
Block a user