* feat: replace manual oauth with better-auth * fix: lint * chore: refactor accounts to unify github + vercel * feat: enhance auth config with host allowlisting Co-Authored-By: open-agents-bot[bot] <260704009+open-agents-bot[bot]@users.noreply.github.com> * fix: add newline at end of manifest.json Co-Authored-By: open-agents-bot[bot] <260704009+open-agents-bot[bot]@users.noreply.github.com> * fix: update betterAuth database schema mappings Co-Authored-By: open-agents-bot[bot] <260704009+open-agents-bot[bot]@users.noreply.github.com> * fix: sanitize redirects and preserve destination in github flow Co-Authored-By: open-agents-bot[bot] <260704009+open-agents-bot[bot]@users.noreply.github.com> * feat: enhance GitHub app callback with installation sync tracking Co-Authored-By: open-agents-bot[bot] <260704009+open-agents-bot[bot]@users.noreply.github.com> * build: add BETTER_AUTH_SECRET to turbo env Co-Authored-By: open-agents-bot[bot] <260704009+open-agents-bot[bot]@users.noreply.github.com> * refactor: update sign-in callback to skip onboarding Co-Authored-By: open-agents-bot[bot] <260704009+open-agents-bot[bot]@users.noreply.github.com> --------- Co-authored-by: nicoalbanese <49612682+nicoalbanese@users.noreply.github.com> Co-authored-by: open-agents-bot[bot] <260704009+open-agents-bot[bot]@users.noreply.github.com>
44 lines
1023 B
TypeScript
44 lines
1023 B
TypeScript
import { NextResponse } from "next/server";
|
|
import { getServerSession } from "@/lib/session/get-server-session";
|
|
import { getUserGitHubToken } from "@/lib/github/token";
|
|
import { fetchGitHubUser } from "@/lib/github/api";
|
|
|
|
export async function GET() {
|
|
const session = await getServerSession();
|
|
|
|
if (!session?.user?.id) {
|
|
return NextResponse.json(
|
|
{ error: "GitHub not connected" },
|
|
{ status: 401 },
|
|
);
|
|
}
|
|
|
|
const token = await getUserGitHubToken(session.user.id);
|
|
|
|
if (!token) {
|
|
return NextResponse.json(
|
|
{ error: "GitHub not connected" },
|
|
{ status: 401 },
|
|
);
|
|
}
|
|
|
|
try {
|
|
const user = await fetchGitHubUser(token);
|
|
|
|
if (!user) {
|
|
return NextResponse.json(
|
|
{ error: "Failed to fetch user" },
|
|
{ status: 500 },
|
|
);
|
|
}
|
|
|
|
return NextResponse.json(user);
|
|
} catch (error) {
|
|
console.error("Error fetching GitHub user:", error);
|
|
return NextResponse.json(
|
|
{ error: "Failed to fetch user" },
|
|
{ status: 500 },
|
|
);
|
|
}
|
|
}
|