Skip to content

Commit af5700c

Browse files
committed
feat: 修复新用户引导页问题,删除之前的tunnel group设计,清理干净前端未用到的资源
1 parent 32bec94 commit af5700c

File tree

67 files changed

+2055
-3092
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+2055
-3092
lines changed

app/components/route-guard.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,17 @@ export function RouteGuard({ children }: RouteGuardProps) {
4343
if (!loading) {
4444
const isPublicRoute = PUBLIC_ROUTES.includes(normalizePath(pathname));
4545

46+
const isSetupGuide = normalizePath(pathname) === '/setup-guide';
47+
4648
console.log('🛡️ RouteGuard 路由检查', {
4749
pathname,
4850
isPublicRoute,
4951
hasUser: !!user,
50-
isSetupGuide: pathname === '/setup-guide',
52+
user: user,
53+
needsSetup: user ? (user as any).needsSetup : 'no user',
54+
isSetupGuide,
5155
action: !user && !isPublicRoute ? '重定向到登录页' :
52-
user && isPublicRoute && pathname !== '/setup-guide' ? '重定向到仪表盘' : '无需重定向'
56+
user && isPublicRoute && !isSetupGuide ? '重定向到仪表盘' : '无需重定向'
5357
});
5458

5559
// 添加小延迟,避免与其他导航操作冲突
@@ -58,13 +62,13 @@ export function RouteGuard({ children }: RouteGuardProps) {
5862
// 用户未登录且访问私有路由,重定向到登录页
5963
console.log('🔒 执行重定向:用户未登录,前往登录页');
6064
router.replace('/login');
61-
} else if (user && isPublicRoute && pathname !== '/setup-guide') {
65+
} else if (user && isPublicRoute && !isSetupGuide) {
6266
// 用户已登录但访问公开路由(如登录页),重定向到仪表盘
6367
// 但是允许已登录用户访问引导页面
6468
console.log('👤 执行重定向:用户已登录,前往仪表盘');
6569
router.replace('/dashboard');
6670
}
67-
}, 50); // 50ms 延迟避免冲突
71+
}, 150); // 增加延迟时间,确保登录跳转有足够时间完成
6872

6973
return () => clearTimeout(timeoutId);
7074
}
@@ -86,7 +90,8 @@ export function RouteGuard({ children }: RouteGuardProps) {
8690

8791
// 检查是否应该显示内容
8892
const isPublicRoute = PUBLIC_ROUTES.includes(normalizePath(pathname));
89-
const shouldShowContent = (user && !isPublicRoute) || (!user && isPublicRoute) || (user && pathname === '/setup-guide');
93+
const isSetupGuide = normalizePath(pathname) === '/setup-guide';
94+
const shouldShowContent = (user && !isPublicRoute) || (!user && isPublicRoute) || (user && isSetupGuide);
9095

9196
if (!shouldShowContent) {
9297
// 正在重定向中,显示加载状态

app/endpoints/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,7 @@ export default function EndpointsPage() {
849849
return;
850850
}
851851
try {
852-
const res = await fetch(buildApiUrl('/api/tunnels/quick'), {
852+
const res = await fetch(buildApiUrl('/api/tunnels/create_by_url'), {
853853
method: 'POST',
854854
headers: {'Content-Type':'application/json'},
855855
body: JSON.stringify({endpointId: selectedEndpoint.id, url: tunnelUrl.trim(), name: tunnelName.trim()})

app/login/page.tsx

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -94,43 +94,32 @@ export default function LoginPage() {
9494
headers: {
9595
'Content-Type': 'application/json',
9696
},
97-
body: JSON.stringify(formData),
97+
body: JSON.stringify(formData)
9898
});
9999

100-
console.log('📡 登录请求响应', {
101-
status: response.status,
102-
ok: response.ok
103-
});
104-
105-
const result = await response.json();
106-
console.log('📋 登录响应数据', result);
107-
108100
if (response.ok) {
101+
const result = await response.json();
102+
console.log('📋 登录响应数据', result);
103+
109104
console.log('✅ 登录成功,设置用户状态并持久化');
110-
// 登录成功后直接设置用户状态并持久化
105+
// 登录成功后设置用户状态并持久化
111106
const loginUser = { username: formData.username };
112107
setUserDirectly(loginUser);
113108
if (typeof window !== 'undefined') {
114109
localStorage.setItem('nodepass.user', JSON.stringify(loginUser));
115110
}
116111

117-
// 检查是否是默认账号密码,如果是则跳转到引导页面
118-
console.log('🔍 检查默认凭据状态', {
119-
isDefaultCredentials: result.isDefaultCredentials,
120-
type: typeof result.isDefaultCredentials
121-
});
122-
123-
if (result.isDefaultCredentials === true) {
124-
console.log('🔧 检测到默认凭据,重定向到安全设置引导页');
125-
console.log('🔍 开始跳转到 /setup-guide');
126-
127-
// 直接使用 window.location 进行跳转,避免与路由守卫冲突
128-
window.location.href = '/setup-guide';
129-
} else {
130-
console.log('🚀 重定向到仪表盘');
131-
router.push('/dashboard');
112+
// 检查是否是默认凭据
113+
if (result.isDefaultCredentials) {
114+
console.log('🔧 检测到默认凭据,跳转到引导页');
115+
router.push('/setup-guide');
116+
return;
132117
}
118+
119+
console.log('🚀 重定向到仪表盘');
120+
router.push('/dashboard');
133121
} else {
122+
const result = await response.json();
134123
console.error('❌ 登录失败', result);
135124
setError(result.error || '登录失败');
136125
}

app/setup-guide/layout.tsx

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
"use client";
2+
3+
import { ReactNode } from 'react';
4+
import { Button } from "@heroui/react";
5+
import { Icon } from "@iconify/react";
6+
import { useTheme } from "next-themes";
7+
8+
interface SetupGuideLayoutProps {
9+
children: ReactNode;
10+
}
11+
12+
export default function SetupGuideLayout({ children }: SetupGuideLayoutProps) {
13+
const { theme, setTheme } = useTheme();
14+
15+
const toggleTheme = () => {
16+
setTheme(theme === 'light' ? 'dark' : 'light');
17+
};
18+
19+
return (
20+
<div className="min-h-screen bg-background relative">
21+
{children}
22+
23+
{/* 浮动主题切换按钮 */}
24+
<Button
25+
isIconOnly
26+
variant="flat"
27+
className="fixed bottom-4 right-4 rounded-full"
28+
onClick={toggleTheme}
29+
aria-label="切换主题"
30+
>
31+
<Icon
32+
icon={theme === 'light' ? "solar:moon-linear" : "solar:sun-2-linear"}
33+
width={24}
34+
className="text-foreground"
35+
/>
36+
</Button>
37+
</div>
38+
);
39+
}

0 commit comments

Comments
 (0)