feat(git): enhance token authentication and credential handling
This commit is contained in:
@@ -73,18 +73,16 @@ export const GitIdentitiesPage: React.FC = () => {
|
||||
|
||||
React.useEffect(() => {
|
||||
if (importData) {
|
||||
// Pre-fill from imported credential
|
||||
// For repo-specific hosts like "github.com/user/repo", use just "repo" as name
|
||||
const parts = importData.host.split('/');
|
||||
const displayName = parts.length >= 3 ? parts[parts.length - 1] : importData.host;
|
||||
|
||||
|
||||
setName(displayName);
|
||||
setUserName(importData.username);
|
||||
setUserEmail('');
|
||||
setAuthType('token');
|
||||
setSshKey('');
|
||||
setHost(importData.host);
|
||||
setColor('string'); // cyan for token-based
|
||||
setColor('string');
|
||||
setIcon('code');
|
||||
} else if (isNewProfile) {
|
||||
setName('');
|
||||
|
||||
@@ -300,18 +300,11 @@ interface DiscoveredCredentialItemProps {
|
||||
onImport: () => void;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get display name for a credential host.
|
||||
* For repo-specific hosts like "github.com/user/repo", returns just "repo".
|
||||
* For host-only like "github.com", returns "github.com".
|
||||
*/
|
||||
const getCredentialDisplayName = (host: string): string => {
|
||||
const parts = host.split('/');
|
||||
if (parts.length >= 3) {
|
||||
// repo-specific: github.com/user/repo -> repo
|
||||
return parts[parts.length - 1];
|
||||
}
|
||||
// host-only: github.com
|
||||
return host;
|
||||
};
|
||||
|
||||
|
||||
@@ -189,7 +189,6 @@ export const GitView: React.FC = () => {
|
||||
loadGlobalIdentity();
|
||||
}, [loadProfiles, loadGlobalIdentity]);
|
||||
|
||||
// Fetch remote URL for filtering token-based identities
|
||||
React.useEffect(() => {
|
||||
if (!currentDirectory || !git?.getRemoteUrl) {
|
||||
setRemoteUrl(null);
|
||||
@@ -505,49 +504,39 @@ export const GitView: React.FC = () => {
|
||||
if (globalIdentity) {
|
||||
unique.set(globalIdentity.id, globalIdentity);
|
||||
}
|
||||
|
||||
// Parse repo host/path from remote URL for filtering token identities
|
||||
// e.g., "git@github.com:user/repo.git" or "https://github.com/user/repo.git"
|
||||
|
||||
let repoHostPath: string | null = null;
|
||||
if (remoteUrl) {
|
||||
try {
|
||||
let normalized = remoteUrl.trim();
|
||||
// Handle SSH format: git@github.com:user/repo.git -> https://github.com/user/repo.git
|
||||
if (normalized.startsWith('git@')) {
|
||||
normalized = 'https://' + normalized.slice(4).replace(':', '/');
|
||||
}
|
||||
// Remove .git suffix
|
||||
if (normalized.endsWith('.git')) {
|
||||
normalized = normalized.slice(0, -4);
|
||||
}
|
||||
const url = new URL(normalized);
|
||||
repoHostPath = url.hostname + url.pathname;
|
||||
} catch {
|
||||
// ignore parse errors
|
||||
}
|
||||
} catch { /* ignore */ }
|
||||
}
|
||||
|
||||
|
||||
for (const profile of profiles) {
|
||||
// SSH identities always shown
|
||||
if (profile.authType !== 'token') {
|
||||
unique.set(profile.id, profile);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Token identities: filter by host match
|
||||
|
||||
const profileHost = profile.host;
|
||||
if (!profileHost) {
|
||||
unique.set(profile.id, profile);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Host-only token (e.g., "github.com") - always show
|
||||
|
||||
if (!profileHost.includes('/')) {
|
||||
unique.set(profile.id, profile);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Repo-specific token - only show if matches current repo
|
||||
|
||||
if (repoHostPath && repoHostPath === profileHost) {
|
||||
unique.set(profile.id, profile);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user