mirror of
https://github.com/mudabbir-ahmad/peworkshop.git
synced 2026-10-08 03:50:21 +00:00
fixed a bit
This commit is contained in:
1 parent
3f75f64cce
commit
22119dbf6f
2 files changed
+44
-6
No files matched your search
@@ -0,0 +1,31 @@
|
||||
// app/api/teams/[teamId]/members/route.js
|
||||
import { query } from '../../../../../lib/db';
|
||||
import { getServerSession } from 'next-auth/next';
|
||||
import { authOptions } from '../../../auth/[...nextauth]/route';
|
||||
|
||||
export async function GET(request, { params }) {
|
||||
const session = await getServerSession(authOptions);
|
||||
|
||||
if (!session) {
|
||||
return Response.json({ error: 'Unauthorised' }, { status: 401 });
|
||||
}
|
||||
|
||||
try {
|
||||
const { teamId } = params;
|
||||
|
||||
// Ensure the user is requesting their own team or is an admin
|
||||
if (session.user.teamId != teamId && session.user.role !== 'admin') {
|
||||
return Response.json({ error: 'Not authorized to view this team' }, { status: 403 });
|
||||
}
|
||||
|
||||
const members = await query(
|
||||
'SELECT id, username FROM users WHERE team_id = ?',
|
||||
[teamId]
|
||||
);
|
||||
|
||||
return Response.json(members);
|
||||
} catch (error) {
|
||||
console.error('Team members fetch error:', error);
|
||||
return Response.json({ error: 'Failed to fetch team members' }, { status: 500 });
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user