为处理中、失败和清理中的配对展示明确状态与恢复动作,支持放弃并清理、作用域内退役冲突连接,并在 Active 状态引导管理员先安全禁用再使用新接入码。同步修复运行时切换后的浏览器会话残留与确认弹窗焦点约束。 验证:pnpm test;pnpm lint;pnpm build。
47 lines
1.3 KiB
TypeScript
47 lines
1.3 KiB
TypeScript
import {
|
|
GatewayApiError,
|
|
getCurrentUser,
|
|
OIDC_BROWSER_SESSION_CREDENTIAL,
|
|
} from '../api';
|
|
|
|
type CurrentUser = Awaited<ReturnType<typeof getCurrentUser>>;
|
|
|
|
export interface RestoredOIDCBrowserSession {
|
|
credential: typeof OIDC_BROWSER_SESSION_CREDENTIAL;
|
|
user: CurrentUser;
|
|
}
|
|
|
|
export interface ReconcileOIDCBrowserSessionOptions {
|
|
credential: string;
|
|
oidcEnabled: boolean;
|
|
onReset: () => void;
|
|
onRestored: (session: RestoredOIDCBrowserSession) => void;
|
|
}
|
|
|
|
export async function restoreOIDCBrowserSession(): Promise<RestoredOIDCBrowserSession | null> {
|
|
try {
|
|
const user = await getCurrentUser(OIDC_BROWSER_SESSION_CREDENTIAL);
|
|
return { credential: OIDC_BROWSER_SESSION_CREDENTIAL, user };
|
|
} catch (error) {
|
|
if (error instanceof GatewayApiError && error.details.status === 401) return null;
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
export async function reconcileOIDCBrowserSessionAfterRuntimeChange(
|
|
options: ReconcileOIDCBrowserSessionOptions,
|
|
): Promise<'ignored' | 'reset' | 'restored'> {
|
|
if (options.credential !== OIDC_BROWSER_SESSION_CREDENTIAL) return 'ignored';
|
|
if (!options.oidcEnabled) {
|
|
options.onReset();
|
|
return 'reset';
|
|
}
|
|
const restored = await restoreOIDCBrowserSession();
|
|
if (!restored) {
|
|
options.onReset();
|
|
return 'reset';
|
|
}
|
|
options.onRestored(restored);
|
|
return 'restored';
|
|
}
|