Fix redirectURI type error in createAuthorizationURL
- Remove redirectURI param from createAuthorizationURL options - Update login route to use USED_CALLBACK_URL from oauth.ts - Enhance update-package.js to fix login route issues 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
069ceb47b2
commit
dd31f9fa4e
@ -1,5 +1,4 @@
|
||||
import { github } from "@/server/auth/oauth";
|
||||
import { OAUTH_CALLBACK_URL } from "@/utils/api-config";
|
||||
import { github, USED_CALLBACK_URL } from "@/server/auth/oauth";
|
||||
import { generateState } from "arctic";
|
||||
import { cookies } from "next/headers";
|
||||
|
||||
@ -9,9 +8,9 @@ export async function GET(): Promise<Response> {
|
||||
const state = generateState();
|
||||
|
||||
// Verwende die zentral definierte Callback-URL
|
||||
// Die redirectURI ist bereits im GitHub-Client konfiguriert
|
||||
const url = await github.createAuthorizationURL(state, {
|
||||
scopes: ["user"],
|
||||
redirectURI: OAUTH_CALLBACK_URL,
|
||||
});
|
||||
const ONE_HOUR = 60 * 60;
|
||||
|
||||
@ -25,7 +24,7 @@ export async function GET(): Promise<Response> {
|
||||
|
||||
// Log zur Fehlersuche
|
||||
console.log(`GitHub OAuth redirect zu: ${url.toString()}`);
|
||||
console.log(`Verwendete Callback-URL: ${OAUTH_CALLBACK_URL}`);
|
||||
console.log(`Verwendete Callback-URL: ${USED_CALLBACK_URL}`);
|
||||
|
||||
return Response.redirect(url);
|
||||
}
|
||||
|
@ -10,8 +10,9 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
// Pfad zur OAuth-Callback-Route und OAuth-Konfiguration
|
||||
// Pfad zur OAuth-Konfiguration und Routes
|
||||
const callbackRoutePath = path.join(__dirname, 'src/app/auth/login/callback/route.ts');
|
||||
const loginRoutePath = path.join(__dirname, 'src/app/auth/login/route.ts');
|
||||
const oauthConfigPath = path.join(__dirname, 'src/server/auth/oauth.ts');
|
||||
|
||||
// Aktualisiere die OAuth-Konfiguration
|
||||
@ -119,4 +120,60 @@ try {
|
||||
console.error('❌ Fehler beim Aktualisieren der package.json:', error);
|
||||
}
|
||||
|
||||
// Aktualisiere die Login-Route
|
||||
try {
|
||||
let loginContent = fs.readFileSync(loginRoutePath, 'utf8');
|
||||
|
||||
// Prüfe, ob Änderungen nötig sind
|
||||
const loginNeedsUpdate =
|
||||
loginContent.includes('redirectURI: OAUTH_CALLBACK_URL') ||
|
||||
!loginContent.includes('USED_CALLBACK_URL');
|
||||
|
||||
if (loginNeedsUpdate) {
|
||||
console.log('✅ Aktualisiere OAuth-Login-Route...');
|
||||
|
||||
// 1. Aktualisiere den Import
|
||||
if (!loginContent.includes('USED_CALLBACK_URL')) {
|
||||
if (loginContent.includes('import { github } from "@/server/auth/oauth";')) {
|
||||
loginContent = loginContent.replace(
|
||||
'import { github } from "@/server/auth/oauth";',
|
||||
'import { github, USED_CALLBACK_URL } from "@/server/auth/oauth";'
|
||||
);
|
||||
}
|
||||
|
||||
// Entferne den OAUTH_CALLBACK_URL-Import
|
||||
if (loginContent.includes('import { OAUTH_CALLBACK_URL } from "@/utils/api-config";')) {
|
||||
loginContent = loginContent.replace(
|
||||
'import { OAUTH_CALLBACK_URL } from "@/utils/api-config";',
|
||||
''
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// 2. Korrigiere die createAuthorizationURL-Funktion
|
||||
if (loginContent.includes('redirectURI: OAUTH_CALLBACK_URL')) {
|
||||
loginContent = loginContent.replace(
|
||||
/const url = await github\.createAuthorizationURL\(state, \{\s*scopes: \["user"\],\s*redirectURI: OAUTH_CALLBACK_URL,\s*\}\);/s,
|
||||
'const url = await github.createAuthorizationURL(state, {\n\t\tscopes: ["user"],\n\t});'
|
||||
);
|
||||
}
|
||||
|
||||
// 3. Aktualisiere die Logging-Nachricht
|
||||
if (loginContent.includes('console.log(`Verwendete Callback-URL: ${OAUTH_CALLBACK_URL}`')) {
|
||||
loginContent = loginContent.replace(
|
||||
'console.log(`Verwendete Callback-URL: ${OAUTH_CALLBACK_URL}`',
|
||||
'console.log(`Verwendete Callback-URL: ${USED_CALLBACK_URL}`'
|
||||
);
|
||||
}
|
||||
|
||||
// Schreibe die aktualisierte Datei
|
||||
fs.writeFileSync(loginRoutePath, loginContent, 'utf8');
|
||||
console.log('✅ OAuth-Login-Route erfolgreich aktualisiert.');
|
||||
} else {
|
||||
console.log('ℹ️ OAuth-Login-Route ist bereits aktuell.');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('❌ Fehler beim Aktualisieren der OAuth-Login-Route:', error);
|
||||
}
|
||||
|
||||
console.log('✅ OAuth-Konfiguration wurde erfolgreich vorbereitet.');
|
Loading…
x
Reference in New Issue
Block a user