Till Tomczak 1348c5479e Fix GitHub OAuth validation type error in callback route
🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-04-01 15:23:57 +02:00

68 lines
2.5 KiB
JavaScript
Executable File
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env node
/**
* Hilfsskript zur Aktualisierung der OAuth-Konfiguration im MYP-Frontend
*
* Dieses Skript wird automatisch beim Build ausgeführt, um sicherzustellen,
* dass die OAuth-Konfiguration korrekt ist.
*/
const fs = require('fs');
const path = require('path');
// Pfad zur OAuth-Callback-Route
const callbackRoutePath = path.join(__dirname, 'src/app/auth/login/callback/route.ts');
// Lese die aktuelle Datei
try {
let content = fs.readFileSync(callbackRoutePath, 'utf8');
// Prüfe, ob die Datei den fehlerhaften Code enthält
if (content.includes('await github.validateAuthorizationCode(code, OAUTH_CALLBACK_URL)')) {
console.log('✅ Aktualisiere OAuth-Callback-Route...');
// Ersetze den fehlerhaften Code
content = content.replace(
/await github\.validateAuthorizationCode\(code, OAUTH_CALLBACK_URL\);/g,
'await github.validateAuthorizationCode(code);'
);
// Aktualisiere auch die Logging-Nachricht
content = content.replace(
/console\.log\(`GitHub OAuth Token-Validierung mit Callback-URL: \${OAUTH_CALLBACK_URL}\`\);/g,
'console.log(`GitHub OAuth Token-Validierung erfolgreich, verwendete Callback-URL: ${github.redirectURI}`);'
);
// Schreibe die aktualisierte Datei
fs.writeFileSync(callbackRoutePath, content, 'utf8');
console.log('✅ OAuth-Callback-Route erfolgreich aktualisiert.');
} else {
console.log(' OAuth-Callback-Route ist bereits aktuell.');
}
} catch (error) {
console.error('❌ Fehler beim Aktualisieren der OAuth-Callback-Route:', error);
}
// Package.json aktualisieren, um das Skript vor dem Build auszuführen
try {
const packageJsonPath = path.join(__dirname, 'package.json');
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
// Prüfe, ob das Skript bereits in den Build-Prozess integriert ist
if (packageJson.scripts.build === 'next build') {
console.log('✅ Aktualisiere package.json...');
// Füge das Skript zum Build-Prozess hinzu
packageJson.scripts.build = 'node update-package.js && next build';
// Schreibe die aktualisierte package.json
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2), 'utf8');
console.log('✅ package.json erfolgreich aktualisiert.');
} else {
console.log(' package.json ist bereits aktualisiert.');
}
} catch (error) {
console.error('❌ Fehler beim Aktualisieren der package.json:', error);
}
console.log('✅ OAuth-Konfiguration wurde erfolgreich vorbereitet.');