重构git凭证托管,改为操作系统托管

This commit is contained in:
xintaofei
2026-03-21 18:00:05 +08:00
parent 44f812c8d2
commit 450b081e88
13 changed files with 180 additions and 19 deletions

View File

@@ -36,6 +36,7 @@ import {
validateGitHubToken,
getGitHubAccounts,
updateGitHubAccounts,
saveAccountToken,
} from "@/lib/tauri"
// ---------------------------------------------------------------------------
@@ -146,14 +147,15 @@ async function saveGenericAccount(
(a) => a.username === creds.username && extractHost(a.server_url) === host
)
if (!isDuplicate) {
const newId = crypto.randomUUID()
await saveAccountToken(newId, creds.password)
await updateGitHubAccounts({
accounts: [
...existing.accounts,
{
id: crypto.randomUUID(),
id: newId,
server_url: serverUrl,
username: creds.username,
token: creds.password,
scopes: [],
avatar_url: null,
is_default: existing.accounts.length === 0,
@@ -284,12 +286,12 @@ export function GitCredentialProvider({ children }: { children: ReactNode }) {
id: crypto.randomUUID(),
server_url: serverUrl,
username: result.username ?? "unknown",
token: trimmedToken,
scopes: result.scopes,
avatar_url: result.avatar_url,
is_default: existing.accounts.length === 0,
created_at: new Date().toISOString(),
}
await saveAccountToken(newAccount.id, trimmedToken)
await updateGitHubAccounts({
accounts: [...existing.accounts, newAccount],
})