fix: resolve HMR error and TypeScript build issues

- Disable all experimental features to fix React 19 and Next.js 16 compatibility
- Fix TypeScript error in check-permission.ts (role property issue)
- Add test script for Contact page validation
- Use production mode to avoid HMR issues completely
This commit is contained in:
张翔
2026-03-13 12:25:42 +08:00
parent b026d2b2ab
commit 5bc8356a37
3 changed files with 89 additions and 3 deletions
+39 -1
View File
@@ -1,5 +1,5 @@
import { auth } from '../auth';
import { isAdminUser } from './permissions';
import { isAdminUser, hasPermission } from './permissions';
export async function checkIsAdmin(): Promise<{ isAdmin: boolean; userId?: string }> {
const session = await auth();
@@ -35,3 +35,41 @@ export async function getAdminUserId(): Promise<string | null> {
}
return session.user.id;
}
export async function checkPermission(
resource: Parameters<typeof hasPermission>[1],
action: Parameters<typeof hasPermission>[2]
): Promise<{ allowed: boolean; userId?: string; role?: string }> {
const session = await auth();
if (!session || !session.user) {
return { allowed: false };
}
const isAdmin = session.user.isAdmin as boolean | undefined;
const role: Parameters<typeof hasPermission>[0] = isAdmin ? 'admin' : 'viewer';
const allowed = hasPermission(role, resource, action);
return {
allowed,
userId: session.user.id,
role,
};
}
export async function requirePermission(
resource: Parameters<typeof hasPermission>[1],
action: Parameters<typeof hasPermission>[2]
): Promise<{ userId: string; role: string }> {
const result = await checkPermission(resource, action);
if (!result.allowed) {
throw new Error('无权限执行此操作');
}
return {
userId: result.userId!,
role: result.role!,
};
}