优化登录功能` (#1386)

* feat(布局): 在导航栏底部添加退出登录按钮

* fix: 使用本地存储的认证信息检查登录

* style(login): 增强可读性
This commit is contained in:
XiaoMiku01 authored and GitHub committed 2025-08-01 09:04:37 +00:00
1 parent b486391e69
commit 795f2965cc
4 files changed
+21 -3

No files matched your search

+2 -1
View File
@@ -39,9 +39,10 @@ export function AuthProvider({ children }: { children: ReactNode }) {
const checkAuthRequired = async () => {
try {
const auth = localStorage.getItem('auth');
const response = await fetch('/api/basic', {
headers: {
'Authorization': 'Basic dGVzdDp0ZXN0' // 使用测试凭据
'Authorization': `Basic ${auth}` // 使用测试凭据
}
});
// 如果返回401,说明需要认证
+2 -1
View File
@@ -14,9 +14,10 @@ export function AuthGuard({ children }: { children: React.ReactNode }) {
// 如果用户未认证,则检查是否需要认证
if (!isAuthenticated) {
// 检查是否需要认证
const auth = localStorage.getItem('auth');
fetch('/api/basic', {
headers: {
'Authorization': 'Basic dGVzdDp0ZXN0' // 使用测试凭据
'Authorization': `Basic ${auth}` // 使用测试凭据
}
}).then(response => {
if (response.status !== 401) {
+12
View File
@@ -279,6 +279,18 @@ export default function ProtectedLayout({ children }: { children: React.ReactNod
</Nav.Header>
<Nav.Footer collapseButton={false}>
<ThemeButton mode={mode} setMode={setMode} systemTheme={systemTheme} />
{typeof window !== 'undefined' && localStorage.getItem('auth') && (
<Button
onClick={() => {
localStorage.removeItem('auth');
window.location.href = '/login';
}}
type="danger"
style={{ marginTop: '10px', width: '100%' }}
>
退出登录
</Button>
)}
</Nav.Footer>
</Nav>
</Sider>
+5 -1
View File
@@ -13,9 +13,10 @@ export default function LoginPage() {
useEffect(() => {
// 检查是否需要认证
const auth = localStorage.getItem('auth');
fetch('/api/basic', {
headers: {
'Authorization': 'Basic dGVzdDp0ZXN0' // 使用测试凭据
'Authorization': `Basic ${auth}` // 使用测试凭据
}
}).then(response => {
if (response.status !== 401) {
@@ -53,6 +54,9 @@ export default function LoginPage() {
height: '100vh',
background: 'linear-gradient(135deg, #667eea 0%, #764ba2 100%)',
backgroundSize: 'cover',
['--semi-color-text-0' as any]: 'rgba(0, 0, 0, 1)',
['--semi-color-text-1' as any]: 'rgba(0, 0, 0, 0.3)',
['--semi-color-text-2' as any]: 'rgba(0, 0, 0, 0.3)',
}}>
<Card
shadows='always'