mirror your GitHub repos to tangled.org automatically
1import { installationAccountLogin } from '#server/utils/github-app'
2
3export interface ConnectInfo {
4 installationId: number
5 login: string | null
6}
7
8/**
9 * Public lookup of an installation's account login for the connect page.
10 * Returns only the login, which the App can already read; it is not a secret
11 * and reveals nothing the install screen didn't. The actual ownership gate is
12 * the GitHub user-OAuth step, not this endpoint.
13 */
14export default defineEventHandler(async (event): Promise<ConnectInfo> => {
15 const raw = getQuery(event).installationId
16 if (typeof raw !== 'string' || !/^\d+$/.test(raw)) {
17 throw createError({ statusCode: 400, statusMessage: 'installationId is required and must be numeric' })
18 }
19 const installationId = Number(raw)
20 return { installationId, login: await installationAccountLogin(installationId) }
21})