Skip to content

Commit 80d59c7

Browse files
committed
api: add extra logging for debugging
1 parent ccfa732 commit 80d59c7

2 files changed

Lines changed: 17 additions & 12 deletions

File tree

.github/workflows/update-contributors.yml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,16 @@ jobs:
1212
steps:
1313
- name: Update Contributors
1414
run: |
15-
echo "Making request to: ${{ secrets.VERCEL_DEPLOYMENT_URL }}/api/updateTopContributors"
16-
echo "Token present: ${{ secrets.FCM_GITHUB_TOKEN != '' }}"
15+
# Ensure token is properly formatted
16+
TOKEN="${FCM_GITHUB_TOKEN}"
17+
echo "Token length: ${#TOKEN}"
18+
echo "Token prefix: ${TOKEN:0:5}..."
1719
1820
response=$(curl -v -X POST ${{ secrets.VERCEL_DEPLOYMENT_URL }}/api/updateTopContributors \
19-
-H "Authorization: Bearer ${{ secrets.FCM_GITHUB_TOKEN }}" \
21+
-H "Authorization: Bearer ${TOKEN}" \
2022
-H "Content-Type: application/json" \
2123
-w "\n%{http_code}")
2224
23-
echo "Full response:"
24-
echo "$response"
25-
2625
status_code=$(echo "$response" | tail -n1)
2726
body=$(echo "$response" | head -n1)
2827

pages/api/updateTopContributors.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ import { storeTopThreeUsersInDb } from '../../utils/fetchTopUsersFromDb';
33

44
export default async function handler(req, res) {
55
console.log('Update contributors API called');
6-
console.log('Auth header present:', !!req.headers.authorization);
7-
console.log('Expected token:', process.env.FCM_GITHUB_TOKEN?.substring(0, 5) + '...');
86

97
const authHeader = req.headers.authorization;
108
if (!authHeader) {
@@ -13,12 +11,19 @@ export default async function handler(req, res) {
1311
}
1412

1513
const token = authHeader.split(' ')[1];
16-
console.log('Received token:', token?.substring(0, 5) + '...');
14+
15+
// Debug logging (first 5 chars only for security)
16+
console.log('Environment token length:', process.env.FCM_GITHUB_TOKEN?.length);
17+
console.log('Received token length:', token?.length);
18+
console.log('Environment token prefix:', process.env.FCM_GITHUB_TOKEN?.substring(0, 5));
19+
console.log('Received token prefix:', token?.substring(0, 5));
1720

1821
if (!token || token !== process.env.FCM_GITHUB_TOKEN) {
19-
console.error('Invalid authorization token');
20-
console.log('Token match:', token === process.env.FCM_GITHUB_TOKEN);
21-
return res.status(401).json({ error: 'Unauthorized' });
22+
console.error('Token validation failed');
23+
return res.status(401).json({
24+
error: 'Unauthorized',
25+
details: 'Token validation failed'
26+
});
2227
}
2328

2429
try {
@@ -40,3 +45,4 @@ export default async function handler(req, res) {
4045
return res.status(500).json({ error: 'Internal server error', details: error.message });
4146
}
4247
}
48+

0 commit comments

Comments
 (0)