Improve admin ban UX, add product cloning, and enhance auth handling

Refines the admin ban page with better dialog state management and feedback during ban/unban actions. Adds a product cloning feature to the products dashboard and updates the product table to support cloning. Improves error handling in ChatDetail for authentication errors, and enhances middleware to handle auth check timeouts and network errors more gracefully. Also updates BanUserCard to validate user ID and ensure correct request formatting.
This commit is contained in:
g
2025-12-27 20:58:08 +00:00
parent 2db13cc9b7
commit c9c3f766a6
7 changed files with 153 additions and 43 deletions

View File

@@ -46,12 +46,28 @@ export async function middleware(req: NextRequest) {
headers.set('Authorization', `Bearer ${token}`);
}
const res = await fetch(authCheckUrl, {
method: "GET",
headers,
credentials: 'include',
signal: AbortSignal.timeout(10000), // 10 second timeout
});
let res: Response;
try {
res = await fetch(authCheckUrl, {
method: "GET",
headers,
credentials: 'include',
signal: AbortSignal.timeout(15000), // 15 second timeout (increased for slower connections)
});
} catch (fetchError) {
// Handle timeout or network errors gracefully
console.error("Middleware: Auth check request failed:", fetchError);
// If it's a timeout or network error, don't redirect - let the request proceed
// The page will handle auth errors client-side
if (fetchError instanceof Error && fetchError.name === 'TimeoutError') {
console.log("Middleware: Auth check timed out, allowing request to proceed");
return NextResponse.next();
}
// For other network errors, redirect to login
return NextResponse.redirect(new URL("/auth/login", req.url));
}
console.log(`Middleware: Auth check responded with status ${res.status}`);
@@ -63,9 +79,11 @@ export async function middleware(req: NextRequest) {
console.log("Middleware: Auth check successful");
// Admin-only protection for /dashboard/admin routes
// Clone the response before reading it to avoid consuming the body
if (pathname.startsWith('/dashboard/admin')) {
try {
const user = await res.json();
const clonedRes = res.clone();
const user = await clonedRes.json();
const username = user?.vendor?.username;
if (username !== 'admin1') {
console.log("Middleware: Non-admin attempted to access /dashboard/admin, redirecting");