Problem:
The job_completion_selfies table was storing an incorrect profile picture URL:
https://undefined.s3.ap-south-1.amazonaws.com/provider_profile_pictures/4/1761742280247_TGCphoto.jpg
Root Cause:
The code was reconstructing the S3 URL using process.env.AWS_S3_BUCKET which was:
- Not set when the code ran (before we added it)
- Unnecessary since the full URL is already stored in the
providerstable
Before (WRONG):
// Reconstructing URL - causes "undefined" if env var not loaded
profilePictureS3Url: `https://${process.env.AWS_S3_BUCKET}.s3.${process.env.AWS_REGION}.amazonaws.com/${profilePictureKey}`After (CORRECT):
// Use the actual URL from database
profilePictureS3Url: profilePictureData.urlFile: backend/services/faceComparisonService.js
New Function:
async getWorkerProfilePictureData(workerId) {
// Returns: { url: "full S3 URL", key: "S3 key" }
// Gets data from providers.profile_picture_url column
}Returns:
{
url: "https://files-and-image-storage-bucket.s3.ap-south-1.amazonaws.com/provider_profile_pictures/4/1761742280247_TGCphoto.jpg",
key: "provider_profile_pictures/4/1761742280247_TGCphoto.jpg"
}File: backend/routes/worker_management/selfieVerification.js
Changes:
- Changed from
getWorkerProfilePictureKey()togetWorkerProfilePictureData() - Use
profilePictureData.urlfor saving to database - Use
profilePictureData.keyfor Rekognition comparison
Code:
// Get both URL and key from database
const profilePictureData = await faceComparisonService.getWorkerProfilePictureData(workerId);
// Use key for face comparison
const faceComparison = await faceComparisonService.compareFaces(s3Key, profilePictureData.key);
// Use URL for database storage
const verificationData = {
profilePictureS3Url: profilePictureData.url, // ✅ Correct URL from database
// ... other fields
};profile_picture_url VARCHAR(500)Stores full S3 URL:
https://files-and-image-storage-bucket.s3.ap-south-1.amazonaws.com/provider_profile_pictures/4/1761742280247_TGCphoto.jpg
profile_picture_s3_url VARCHAR(500)Now stores correct URL:
https://files-and-image-storage-bucket.s3.ap-south-1.amazonaws.com/provider_profile_pictures/4/1761742280247_TGCphoto.jpg
Before (WRONG):
https://undefined.s3.ap-south-1.amazonaws.com/provider_profile_pictures/4/1761742280247_TGCphoto.jpg
1. Worker uploads profile picture
↓
2. Stored in: files-and-image-storage-bucket
↓
3. Full URL saved to: providers.profile_picture_url
↓
4. Worker completes job and uploads selfie
↓
5. System calls: getWorkerProfilePictureData(workerId)
↓
6. Returns: { url: "full URL", key: "S3 key" }
↓
7. Face comparison uses: profilePictureData.key
↓
8. Database saves: profilePictureData.url
↓
9. job_completion_selfies.profile_picture_s3_url = correct URL ✅
# Backend should auto-reload with nodemon
# Check console for confirmationWorker ID 4 (has profile picture):
- Complete a job
- Upload selfie
- Check database
SELECT
booking_id,
worker_id,
profile_picture_s3_url,
verification_status
FROM job_completion_selfies
WHERE worker_id = 4
ORDER BY created_at DESC
LIMIT 1;Expected Result:
profile_picture_s3_url: https://files-and-image-storage-bucket.s3.ap-south-1.amazonaws.com/provider_profile_pictures/4/1761742280247_TGCphoto.jpg
NOT:
profile_picture_s3_url: https://undefined.s3.ap-south-1.amazonaws.com/...
You should see:
[Selfie Verification] Checking profile picture for worker ID: 4
[Profile Picture] Found URL for provider 4: https://files-and-image-storage-bucket.s3.ap-south-1.amazonaws.com/provider_profile_pictures/4/1761742280247_TGCphoto.jpg
[Profile Picture] Extracted S3 key: provider_profile_pictures/4/1761742280247_TGCphoto.jpg
[Selfie Verification] Profile picture found for worker ID: 4 {
key: 'provider_profile_pictures/4/1761742280247_TGCphoto.jpg',
url: 'https://files-and-image-storage-bucket.s3.ap-south-1.amazonaws.com/provider_profile_pictures/4/1761742280247_TGCphoto.jpg'
}
[Face Comparison] Starting face comparison: {
selfieKey: 'selfie_verifications/4/...',
selfieBucket: 'worker-verification-images',
profileKey: 'provider_profile_pictures/4/1761742280247_TGCphoto.jpg',
profileBucket: 'files-and-image-storage-bucket',
threshold: 80,
region: 'ap-south-1'
}- ✅ No more "undefined" in bucket name
- ✅ Uses actual URL from database
- ✅ Consistent with how profile pictures are stored
- ✅ Database is the source of truth for URLs
- ✅ No need to reconstruct URLs
- ✅ Handles different bucket names automatically
- ✅ Logs show both URL and key
- ✅ Easy to verify what's being used
- ✅ Clear error messages
- ✅ Old function still exists (deprecated)
- ✅ New function provides more data
- ✅ No breaking changes to other code
Modified:
backend/routes/worker_management/selfieVerification.js- Uses new functionbackend/services/faceComparisonService.js- Added getWorkerProfilePictureData()backend/.env- Added AWS_S3_BUCKET (for Rekognition access)
Database Tables:
providers- Source of profile picture URLsjob_completion_selfies- Stores verification data
// Code was doing this:
profilePictureS3Url: `https://${process.env.AWS_S3_BUCKET}.s3...`
// Result: https://undefined.s3.ap-south-1.amazonaws.com/...// Now doing this:
profilePictureS3Url: profilePictureData.url
// Result: https://files-and-image-storage-bucket.s3.ap-south-1.amazonaws.com/...Don't reconstruct what you already have! The full URL is stored in the database, so just use it directly.
- ✅ Code fixed
- ✅ New function created
- ✅ Logging enhanced
- ✅ Ready to test
Next selfie upload will have the correct profile picture URL! 🎉