Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 4 additions & 25 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 5 additions & 57 deletions src/app/api/auth/github/callback/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,60 +21,6 @@ export async function GET(request: Request) {
);
}

const clientId = process.env.GITHUB_ID;
const clientSecret = process.env.GITHUB_SECRET;

if (!clientId || !clientSecret) {
return NextResponse.json(
{ error: "GitHub OAuth not properly configured" },
{ status: 500 }
);
}

const appUrl = process.env.NEXT_PUBLIC_APP_URL || "https://vortexis-dev.vercel.app";
const redirectUri = `${appUrl}/auth/callback`;

// Exchange authorization code for GitHub access token
const tokenResponse = await fetch("https://github.com/login/oauth/access_token", {
method: "POST",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
},
body: JSON.stringify({
client_id: clientId,
client_secret: clientSecret,
code,
redirect_uri: redirectUri,
}),
});

if (!tokenResponse.ok) {
console.error("[GitHub Callback] Token exchange failed:", tokenResponse.status);
return NextResponse.json(
{ error: "Failed to exchange authorization code" },
{ status: 400 }
);
}

const tokenData = await tokenResponse.json();

if (tokenData.error) {
console.error("[GitHub Callback] GitHub token error:", tokenData.error, tokenData.error_description);
return NextResponse.json(
{ error: tokenData.error_description || tokenData.error },
{ status: 400 }
);
}

const githubAccessToken = tokenData.access_token;
if (!githubAccessToken) {
return NextResponse.json(
{ error: "No access token in GitHub response" },
{ status: 400 }
);
}

const baseUrl = process.env.NEXT_PUBLIC_BASE_URL;
if (!baseUrl) {
return NextResponse.json(
Expand All @@ -83,11 +29,14 @@ export async function GET(request: Request) {
);
}

// Send GitHub access token to backend
const appUrl = process.env.NEXT_PUBLIC_APP_URL || "https://vortexis-dev.vercel.app";
const redirectUri = `${appUrl}/auth/callback`;

// Send raw auth code + redirect_uri to backend — backend does the GitHub token exchange
const res = await fetch(`${baseUrl}/auth/github`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ access_token: githubAccessToken }),
body: JSON.stringify({ code, redirect_uri: redirectUri }),
});

if (!res.ok) {
Expand Down Expand Up @@ -128,7 +77,6 @@ export async function GET(request: Request) {
);
}

// Set secure HTTP-only cookies for tokens
const cookieStore = await cookies();
const threeDaysInSeconds = 3 * 24 * 60 * 60;

Expand Down