fix: gate password sessions on the login method so data-source sessions also get the passkey-only page [CI SKIP]

This commit is contained in:
justme committed 2026-10-08 04:09:39 +08:00
1 parent 3b88a3419d
commit 4a3631f82b
2 files changed
+4 -7

No files matched your search

+3 -2
View File
@@ -244,7 +244,8 @@ export function App() {
}
if (!me) return <Login />
// 密码登录的会话没有任何能力:只给它添加 Passkey 的页面
if (me.kind === 'session' && me.auth_method === 'password') return <PasskeyOnly />
// 以数据源方式(会话令牌)连别的后端时 kind 是 token,所以只看登录方式
if (me.auth_method === 'password') return <PasskeyOnly />
return (
<div className="shell">
@@ -271,7 +272,7 @@ export function App() {
<span className="grow">
<div style={{ fontWeight: 600 }}>{me.username ?? 'API 令牌'}</div>
<div className="faint" style={{ fontSize: 12 }}>
{me.kind === 'token' ? `API 令牌 · ${me.capabilities.length} 项能力` : '管理员'}
{me.kind === 'token' && !me.auth_method ? `API 令牌 · ${me.capabilities.length} 项能力` : '管理员'}
</div>
</span>
<ThemeToggle />
+1 -5
View File
@@ -1,7 +1,6 @@
import { KeyRound, LogOut } from 'lucide-react'
import { useEffect, useState } from 'react'
import { api } from '@shared/api/client'
import { getBase } from '@shared/api/source'
import type { Page, PasskeyDto } from '@shared/api/types'
import { passkeySupported } from '@shared/api/webauthn'
import { useAuth } from './auth'
@@ -23,7 +22,6 @@ export function PasskeyOnly() {
}
useEffect(load, [])
const remote = !!getBase()
return (
<div className="login">
<div className="card stack" style={{ maxWidth: 520 }}>
@@ -34,9 +32,7 @@ export function PasskeyOnly() {
</p>
</div>
<div className="notice">用密码登录的会话不能管理任何东西,只能添加 Passkey。添加之后退出,用 Passkey 重新登录。</div>
{remote ? (
<div className="notice warn">这是另一个后端:Passkey 绑定在后端自己的域名上,请直接打开那个后端的管理端地址再登录。</div>
) : !passkeySupported() ? (
{!passkeySupported() ? (
<div className="notice warn">这个浏览器不支持 Passkey(需要 HTTPS 或 localhost)。</div>
) : count === 0 || count === null ? (
<div className="stack">