feat: 实现用户登录认证与权限控制系统
- 新增用户登录页面与API端点(/api/auth/login、/api/auth/logout、/api/auth/me) - 引入基于密码哈希的认证机制,支持默认管理员账号登录 - 创建访问控制模块(lib/access-control.ts),实现基于角色的权限验证 - 在现有API端点中集成权限检查,限制非管理员用户只能访问其所属项目数据 - 更新应用布局,要求用户登录后才能访问主界面 - 扩展用户表结构,增加用户名和密码哈希字段 - 调整项目、KR、目标、会议记录等资源的查询逻辑,根据用户权限过滤数据 - 改进管理页面(指标、模板)的删除操作,使用确认对话框替代直接确认 - 优化“我的KR”页面,为管理员提供全员KR概览视图 - 修复.gitignore文件中的拼写错误(.trae → .travis) - 添加数据库迁移脚本,支持任务直接关联项目、禁用RLS、添加求助字段等 - 配置Next.js以支持独立输出和子路径部署
This commit is contained in:
@@ -2,26 +2,20 @@
|
||||
|
||||
import { useState, useEffect, ReactNode } from 'react';
|
||||
import { UserProvider, useUser } from './user-context';
|
||||
import { UserSwitcher } from './user-switcher';
|
||||
import { MainNav } from './main-nav';
|
||||
import { InitWizard } from './init-wizard';
|
||||
import { Loader2 } from 'lucide-react';
|
||||
import { usePathname, useRouter } from 'next/navigation';
|
||||
|
||||
function AppContent({ children }: { children: ReactNode }) {
|
||||
const { isLoading, isInitialized, users, refreshUsers } = useUser();
|
||||
const [showWizard, setShowWizard] = useState(false);
|
||||
const { isLoading, isInitialized, isAuthenticated } = useUser();
|
||||
const pathname = usePathname();
|
||||
const router = useRouter();
|
||||
|
||||
useEffect(() => {
|
||||
if (!isLoading && users.length === 0) {
|
||||
setShowWizard(true);
|
||||
if (!isLoading && isInitialized && !isAuthenticated && pathname !== '/login') {
|
||||
router.replace('/login');
|
||||
}
|
||||
}, [isLoading, users.length]);
|
||||
|
||||
const handleInitComplete = async () => {
|
||||
await refreshUsers();
|
||||
setShowWizard(false);
|
||||
window.location.reload();
|
||||
};
|
||||
}, [isAuthenticated, isInitialized, isLoading, pathname, router]);
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
@@ -34,10 +28,6 @@ function AppContent({ children }: { children: ReactNode }) {
|
||||
);
|
||||
}
|
||||
|
||||
if (showWizard) {
|
||||
return <InitWizard onComplete={handleInitComplete} />;
|
||||
}
|
||||
|
||||
if (!isInitialized) {
|
||||
return (
|
||||
<div className="min-h-screen flex items-center justify-center">
|
||||
@@ -49,13 +39,27 @@ function AppContent({ children }: { children: ReactNode }) {
|
||||
);
|
||||
}
|
||||
|
||||
if (pathname === '/login') {
|
||||
return <>{children}</>;
|
||||
}
|
||||
|
||||
if (!isAuthenticated) {
|
||||
return (
|
||||
<div className="min-h-screen flex items-center justify-center">
|
||||
<div className="flex flex-col items-center gap-3">
|
||||
<Loader2 className="h-8 w-8 animate-spin text-teal-600" />
|
||||
<p className="text-sm text-muted-foreground">跳转登录...</p>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<MainNav />
|
||||
<main className="pt-14 pb-24 min-h-screen bg-slate-50">
|
||||
{children}
|
||||
</main>
|
||||
<UserSwitcher />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user