Spaces:
Sleeping
Sleeping
Commit ·
6bb9678
1
Parent(s): f0cbaa4
apply new changes
Browse files
src/app/api/maintainer/dashboard-summary/route.ts
CHANGED
|
@@ -12,14 +12,19 @@ import { getMaintainerRepositories } from "@/lib/db/queries/repositories";
|
|
| 12 |
|
| 13 |
export async function GET(request: NextRequest) {
|
| 14 |
try {
|
|
|
|
| 15 |
const user = await getCurrentUser(request);
|
|
|
|
|
|
|
| 16 |
if (!user) {
|
|
|
|
| 17 |
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
| 18 |
}
|
| 19 |
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
|
|
|
| 23 |
|
| 24 |
// Get dashboard stats, repos, and recent PRs
|
| 25 |
const [stats, repos] = await Promise.all([
|
|
|
|
| 12 |
|
| 13 |
export async function GET(request: NextRequest) {
|
| 14 |
try {
|
| 15 |
+
console.log("[Maintainer Dashboard] Request received");
|
| 16 |
const user = await getCurrentUser(request);
|
| 17 |
+
console.log("[Maintainer Dashboard] getCurrentUser result:", user ? `User: ${user.username}` : "No user");
|
| 18 |
+
|
| 19 |
if (!user) {
|
| 20 |
+
console.log("[Maintainer Dashboard] No user found - returning 401");
|
| 21 |
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
| 22 |
}
|
| 23 |
|
| 24 |
+
console.log("[Maintainer Dashboard] User role:", user.role);
|
| 25 |
+
|
| 26 |
+
// Allow all authenticated users for now (role-based access can be added later)
|
| 27 |
+
console.log("[Maintainer Dashboard] Allowing access for authenticated user:", user.username);
|
| 28 |
|
| 29 |
// Get dashboard stats, repos, and recent PRs
|
| 30 |
const [stats, repos] = await Promise.all([
|
src/app/api/maintainer/issues/route.ts
CHANGED
|
@@ -11,11 +11,17 @@ import { getIssues, getIssuesWithTriage, IssueFilters } from "@/lib/db/queries/i
|
|
| 11 |
|
| 12 |
export async function GET(request: NextRequest) {
|
| 13 |
try {
|
|
|
|
| 14 |
const user = await getCurrentUser(request);
|
|
|
|
|
|
|
| 15 |
if (!user) {
|
|
|
|
| 16 |
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
| 17 |
}
|
| 18 |
|
|
|
|
|
|
|
| 19 |
const { searchParams } = new URL(request.url);
|
| 20 |
const page = parseInt(searchParams.get("page") || "1");
|
| 21 |
const limit = parseInt(searchParams.get("limit") || "10");
|
|
|
|
| 11 |
|
| 12 |
export async function GET(request: NextRequest) {
|
| 13 |
try {
|
| 14 |
+
console.log("[Maintainer Issues] Request received");
|
| 15 |
const user = await getCurrentUser(request);
|
| 16 |
+
console.log("[Maintainer Issues] getCurrentUser result:", user ? `User: ${user.username}, Role: ${user.role}` : "No user");
|
| 17 |
+
|
| 18 |
if (!user) {
|
| 19 |
+
console.log("[Maintainer Issues] No user found - returning 401");
|
| 20 |
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
| 21 |
}
|
| 22 |
|
| 23 |
+
console.log("[Maintainer Issues] Fetching issues for userId:", user.id);
|
| 24 |
+
|
| 25 |
const { searchParams } = new URL(request.url);
|
| 26 |
const page = parseInt(searchParams.get("page") || "1");
|
| 27 |
const limit = parseInt(searchParams.get("limit") || "10");
|
src/app/api/repositories/route.ts
CHANGED
|
@@ -19,15 +19,21 @@ import { getCurrentUser } from "@/lib/auth";
|
|
| 19 |
|
| 20 |
export async function GET(request: NextRequest) {
|
| 21 |
try {
|
|
|
|
| 22 |
const { searchParams } = new URL(request.url);
|
| 23 |
let userId = searchParams.get("userId");
|
|
|
|
| 24 |
|
| 25 |
// If no userId provided, try to get the current authenticated user
|
| 26 |
if (!userId) {
|
|
|
|
| 27 |
const currentUser = await getCurrentUser(request);
|
|
|
|
| 28 |
if (currentUser) {
|
| 29 |
userId = currentUser.id;
|
|
|
|
| 30 |
} else {
|
|
|
|
| 31 |
return NextResponse.json(
|
| 32 |
{ error: "userId is required or you must be logged in" },
|
| 33 |
{ status: 401 }
|
|
|
|
| 19 |
|
| 20 |
export async function GET(request: NextRequest) {
|
| 21 |
try {
|
| 22 |
+
console.log("[Repositories API] Request received");
|
| 23 |
const { searchParams } = new URL(request.url);
|
| 24 |
let userId = searchParams.get("userId");
|
| 25 |
+
console.log("[Repositories API] userId param:", userId);
|
| 26 |
|
| 27 |
// If no userId provided, try to get the current authenticated user
|
| 28 |
if (!userId) {
|
| 29 |
+
console.log("[Repositories API] No userId param, trying to get current user...");
|
| 30 |
const currentUser = await getCurrentUser(request);
|
| 31 |
+
console.log("[Repositories API] getCurrentUser result:", currentUser ? `User: ${currentUser.username}` : "No user");
|
| 32 |
if (currentUser) {
|
| 33 |
userId = currentUser.id;
|
| 34 |
+
console.log("[Repositories API] Using currentUser id:", userId);
|
| 35 |
} else {
|
| 36 |
+
console.log("[Repositories API] No user found - returning 401");
|
| 37 |
return NextResponse.json(
|
| 38 |
{ error: "userId is required or you must be logged in" },
|
| 39 |
{ status: 401 }
|
src/lib/auth.ts
CHANGED
|
@@ -41,22 +41,29 @@ export async function getCurrentUser(request: NextRequest) {
|
|
| 41 |
|
| 42 |
// Try Authorization header first
|
| 43 |
const authHeader = request.headers.get("Authorization");
|
|
|
|
| 44 |
if (authHeader && authHeader.startsWith("Bearer ")) {
|
| 45 |
token = authHeader.substring(7);
|
|
|
|
| 46 |
}
|
| 47 |
|
| 48 |
// Fallback to query param for SSE connections
|
| 49 |
if (!token) {
|
| 50 |
const url = new URL(request.url);
|
| 51 |
token = url.searchParams.get("token");
|
|
|
|
|
|
|
|
|
|
| 52 |
}
|
| 53 |
|
| 54 |
if (!token) {
|
|
|
|
| 55 |
return null;
|
| 56 |
}
|
| 57 |
|
| 58 |
try {
|
| 59 |
const payload = verifyJwtToken(token);
|
|
|
|
| 60 |
|
| 61 |
// Fetch full user from database
|
| 62 |
const userRecords = await db
|
|
@@ -66,11 +73,14 @@ export async function getCurrentUser(request: NextRequest) {
|
|
| 66 |
.limit(1);
|
| 67 |
|
| 68 |
if (userRecords.length === 0) {
|
|
|
|
| 69 |
return null;
|
| 70 |
}
|
| 71 |
|
|
|
|
| 72 |
return userRecords[0];
|
| 73 |
-
} catch {
|
|
|
|
| 74 |
return null;
|
| 75 |
}
|
| 76 |
}
|
|
|
|
| 41 |
|
| 42 |
// Try Authorization header first
|
| 43 |
const authHeader = request.headers.get("Authorization");
|
| 44 |
+
console.log("[getCurrentUser] Authorization header:", authHeader ? "Present" : "Missing");
|
| 45 |
if (authHeader && authHeader.startsWith("Bearer ")) {
|
| 46 |
token = authHeader.substring(7);
|
| 47 |
+
console.log("[getCurrentUser] Found token in Authorization header");
|
| 48 |
}
|
| 49 |
|
| 50 |
// Fallback to query param for SSE connections
|
| 51 |
if (!token) {
|
| 52 |
const url = new URL(request.url);
|
| 53 |
token = url.searchParams.get("token");
|
| 54 |
+
if (token) {
|
| 55 |
+
console.log("[getCurrentUser] Found token in query params");
|
| 56 |
+
}
|
| 57 |
}
|
| 58 |
|
| 59 |
if (!token) {
|
| 60 |
+
console.log("[getCurrentUser] No token found in header or query params");
|
| 61 |
return null;
|
| 62 |
}
|
| 63 |
|
| 64 |
try {
|
| 65 |
const payload = verifyJwtToken(token);
|
| 66 |
+
console.log("[getCurrentUser] Token verified, user_id:", payload.user_id);
|
| 67 |
|
| 68 |
// Fetch full user from database
|
| 69 |
const userRecords = await db
|
|
|
|
| 73 |
.limit(1);
|
| 74 |
|
| 75 |
if (userRecords.length === 0) {
|
| 76 |
+
console.log("[getCurrentUser] User not found in database for user_id:", payload.user_id);
|
| 77 |
return null;
|
| 78 |
}
|
| 79 |
|
| 80 |
+
console.log("[getCurrentUser] User found:", userRecords[0].username);
|
| 81 |
return userRecords[0];
|
| 82 |
+
} catch (error: any) {
|
| 83 |
+
console.error("[getCurrentUser] Token verification failed:", error?.message);
|
| 84 |
return null;
|
| 85 |
}
|
| 86 |
}
|