mirror of
https://github.com/RayLabsHQ/gitea-mirror.git
synced 2025-12-07 12:06:46 +03:00
Release v3.2.4 - Fix metadata mirroring authentication issues
Fixed critical authentication issue causing "user does not exist [uid: 0]" errors during metadata mirroring operations. This release addresses Issue #68 and ensures proper authentication validation before all Gitea operations. Key improvements: - Pre-flight authentication validation for all Gitea operations - Consistent token decryption across all API calls - Repository existence verification before metadata operations - Graceful fallback to user account when org creation fails - Enhanced error messages with specific troubleshooting guidance - Added diagnostic test scripts for authentication validation This patch ensures metadata mirroring (issues, PRs, labels, milestones) works reliably without authentication errors.
This commit is contained in:
@@ -85,6 +85,25 @@ export async function getOrCreateGiteaOrgEnhanced({
|
||||
|
||||
const decryptedConfig = decryptConfigTokens(config as Config);
|
||||
|
||||
// First, validate the user's authentication by getting their information
|
||||
console.log(`[Org Creation] Validating user authentication before organization operations`);
|
||||
try {
|
||||
const userResponse = await httpGet(
|
||||
`${config.giteaConfig.url}/api/v1/user`,
|
||||
{
|
||||
Authorization: `token ${decryptedConfig.giteaConfig.token}`,
|
||||
}
|
||||
);
|
||||
console.log(`[Org Creation] Authenticated as user: ${userResponse.data.username || userResponse.data.login} (ID: ${userResponse.data.id})`);
|
||||
} catch (authError) {
|
||||
if (authError instanceof HttpError && authError.status === 401) {
|
||||
console.error(`[Org Creation] Authentication failed: Invalid or expired token`);
|
||||
throw new Error(`Authentication failed: Please check your Gitea token has the required permissions. The token may be invalid or expired.`);
|
||||
}
|
||||
console.error(`[Org Creation] Failed to validate authentication:`, authError);
|
||||
throw new Error(`Failed to validate Gitea authentication: ${authError instanceof Error ? authError.message : String(authError)}`);
|
||||
}
|
||||
|
||||
for (let attempt = 0; attempt < maxRetries; attempt++) {
|
||||
try {
|
||||
console.log(`[Org Creation] Attempting to get or create organization: ${orgName} (attempt ${attempt + 1}/${maxRetries})`);
|
||||
@@ -164,6 +183,18 @@ export async function getOrCreateGiteaOrgEnhanced({
|
||||
}
|
||||
continue; // Retry the loop
|
||||
}
|
||||
|
||||
// Check for permission errors
|
||||
if (createError.status === 403) {
|
||||
console.error(`[Org Creation] Permission denied: User may not have rights to create organizations`);
|
||||
throw new Error(`Permission denied: Your Gitea user account does not have permission to create organizations. Please ensure your account has the necessary privileges or contact your Gitea administrator.`);
|
||||
}
|
||||
|
||||
// Check for authentication errors
|
||||
if (createError.status === 401) {
|
||||
console.error(`[Org Creation] Authentication failed when creating organization`);
|
||||
throw new Error(`Authentication failed: The Gitea token does not have sufficient permissions to create organizations. Please ensure your token has 'write:organization' scope.`);
|
||||
}
|
||||
}
|
||||
throw createError;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user