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:
@@ -4,6 +4,8 @@ import Link from 'next/link';
|
||||
import { usePathname } from 'next/navigation';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { useUser } from './user-context';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import {
|
||||
LayoutDashboard,
|
||||
FolderKanban,
|
||||
@@ -13,12 +15,14 @@ import {
|
||||
Users,
|
||||
Gauge,
|
||||
Files,
|
||||
CheckSquare,
|
||||
} from 'lucide-react';
|
||||
|
||||
const mainNavItems = [
|
||||
{ href: '/', label: '驾驶舱', icon: LayoutDashboard },
|
||||
{ href: '/', label: '总览', icon: LayoutDashboard },
|
||||
{ href: '/projects', label: '项目', icon: FolderKanban },
|
||||
{ href: '/my-krs', label: '我的KR', icon: Target },
|
||||
{ href: '/my-tasks', label: '我的计划', icon: CheckSquare },
|
||||
{ href: '/meeting', label: '例会', icon: CalendarClock },
|
||||
{ href: '/analysis', label: '分析', icon: BarChart3 },
|
||||
];
|
||||
@@ -31,7 +35,8 @@ const adminNavItems = [
|
||||
|
||||
export function MainNav() {
|
||||
const pathname = usePathname();
|
||||
const { currentUser } = useUser();
|
||||
const router = useRouter();
|
||||
const { currentUser, logout } = useUser();
|
||||
const isOwner = currentUser?.role === 'owner';
|
||||
|
||||
return (
|
||||
@@ -41,7 +46,7 @@ export function MainNav() {
|
||||
<div className="flex items-center gap-6">
|
||||
<Link href="/" className="flex items-center gap-2 font-bold text-lg">
|
||||
<Target className="h-6 w-6 text-teal-600" />
|
||||
<span className="text-slate-800">OKR 执行系统</span>
|
||||
<span className="text-slate-800">兜爸目标管理</span>
|
||||
</Link>
|
||||
<div className="hidden md:flex items-center gap-1">
|
||||
{mainNavItems.map((item) => {
|
||||
@@ -67,30 +72,46 @@ export function MainNav() {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{isOwner && (
|
||||
<div className="flex items-center gap-1">
|
||||
<span className="text-xs text-muted-foreground mr-2 hidden lg:block">管理</span>
|
||||
{adminNavItems.map((item) => {
|
||||
const Icon = item.icon;
|
||||
const isActive = pathname === item.href;
|
||||
return (
|
||||
<Link
|
||||
key={item.href}
|
||||
href={item.href}
|
||||
className={cn(
|
||||
'flex items-center gap-2 px-3 py-2 rounded-md text-sm font-medium transition-colors',
|
||||
isActive
|
||||
? 'bg-slate-800 text-white'
|
||||
: 'text-slate-600 hover:bg-slate-100 hover:text-slate-900'
|
||||
)}
|
||||
>
|
||||
<Icon className="h-4 w-4" />
|
||||
<span className="hidden lg:inline">{item.label}</span>
|
||||
</Link>
|
||||
);
|
||||
})}
|
||||
<div className="flex items-center gap-3">
|
||||
{isOwner && (
|
||||
<div className="flex items-center gap-1">
|
||||
<span className="text-xs text-muted-foreground mr-2 hidden lg:block">管理</span>
|
||||
{adminNavItems.map((item) => {
|
||||
const Icon = item.icon;
|
||||
const isActive = pathname === item.href;
|
||||
return (
|
||||
<Link
|
||||
key={item.href}
|
||||
href={item.href}
|
||||
className={cn(
|
||||
'flex items-center gap-2 px-3 py-2 rounded-md text-sm font-medium transition-colors',
|
||||
isActive
|
||||
? 'bg-slate-800 text-white'
|
||||
: 'text-slate-600 hover:bg-slate-100 hover:text-slate-900'
|
||||
)}
|
||||
>
|
||||
<Icon className="h-4 w-4" />
|
||||
<span className="hidden lg:inline">{item.label}</span>
|
||||
</Link>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="text-sm text-slate-700 hidden sm:inline">{currentUser?.name}</span>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => {
|
||||
logout();
|
||||
router.replace('/login');
|
||||
}}
|
||||
>
|
||||
退出
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
Reference in New Issue
Block a user