From 596bba2c1b876bbcd9663990fb4a7f9fc89a865d Mon Sep 17 00:00:00 2001 From: paul Date: Fri, 25 Jul 2025 13:20:44 +0200 Subject: [PATCH] Fix permission error when writing admin credentials - Changed credential file location from /app/ to /app/data/ - Added directory creation with recursive flag - Updated console messages to show correct file location - The data/ directory is already owned by nodejs user in Dockerfile The error occurred because the nodejs user doesn't have write permission to /app/ directory, but does have permission to /app/data/ which is explicitly created and chowned in the Dockerfile. --- DEPLOYMENT_GUIDE.md | 2 +- backend/migrations/core/001_init.js | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/DEPLOYMENT_GUIDE.md b/DEPLOYMENT_GUIDE.md index bc115b7..6f40d3d 100644 --- a/DEPLOYMENT_GUIDE.md +++ b/DEPLOYMENT_GUIDE.md @@ -180,7 +180,7 @@ docker-compose up -d # Run database migrations docker-compose exec backend npm run migrate -# Admin credentials will be displayed and saved to ADMIN_CREDENTIALS.txt +# Admin credentials will be displayed and saved to /data/ADMIN_CREDENTIALS.txt ``` #### Step 4: Configure Nginx diff --git a/backend/migrations/core/001_init.js b/backend/migrations/core/001_init.js index 6efe491..9471d8f 100644 --- a/backend/migrations/core/001_init.js +++ b/backend/migrations/core/001_init.js @@ -26,7 +26,15 @@ exports.up = async function(knex) { }); // Save the generated password to a file for the user to retrieve - const setupInfoPath = path.join(__dirname, '..', '..', 'ADMIN_CREDENTIALS.txt'); + const dataDir = path.join(__dirname, '..', '..', 'data'); + const setupInfoPath = path.join(dataDir, 'ADMIN_CREDENTIALS.txt'); + + // Ensure data directory exists + try { + await fs.mkdir(dataDir, { recursive: true }); + } catch (error) { + // Directory might already exist, that's okay + } const setupInfo = ` ======================================== PicPeak Admin Credentials @@ -58,8 +66,8 @@ Generated on: ${new Date().toISOString()} console.log(`Password: ${generatedPassword}`); console.log('\n⚠️ IMPORTANT:'); console.log('1. Save these credentials securely'); - console.log('2. You will be required to change the password on first login'); - console.log('3. Credentials are also saved in: ADMIN_CREDENTIALS.txt'); + console.log('2. Please change the password after first login'); + console.log('3. Credentials are also saved in: data/ADMIN_CREDENTIALS.txt'); console.log('========================================\n'); }