This commit is contained in:
2026-05-19 12:00:00 +02:00
parent 6bd3b76782
commit ed4bf9a0ee
28 changed files with 2762 additions and 12 deletions

View File

@@ -0,0 +1,34 @@
import { redirect, error } from '@sveltejs/kit';
import { db } from '$lib/server/db';
import { githubInstallation } from '$lib/server/db/schema';
import { decodeInstallState, getGitHubInstallation } from '$lib/server/github-app';
export const GET = async ({ url, locals }) => {
const installationId = url.searchParams.get('installation_id');
const state = decodeInstallState(url.searchParams.get('state') ?? undefined);
if (!installationId) throw error(400, 'Missing installation_id');
if (!state.userId) throw error(400, 'Missing install state');
if (!locals.user || locals.user.id !== state.userId) throw redirect(302, '/auth/login');
const installation = await getGitHubInstallation(installationId);
const accountLogin = installation.account?.login ?? 'github';
await db
.insert(githubInstallation)
.values({
userId: locals.user.id,
installationId,
accountLogin
})
.onConflictDoUpdate({
target: githubInstallation.installationId,
set: {
userId: locals.user.id,
accountLogin,
updatedAt: new Date()
}
});
throw redirect(303, state.redirect);
};