mirror your GitHub repos to tangled.org automatically
1export default defineEventHandler(async event => {
2 const query = getQuery(event)
3 const handleRaw = query.handle
4 const installationIdRaw = query.installationId
5
6 if (typeof handleRaw !== 'string' || !handleRaw.trim()) {
7 throw createError({ statusCode: 400, statusMessage: 'handle is required' })
8 }
9 if (typeof installationIdRaw !== 'string' || !/^\d+$/.test(installationIdRaw)) {
10 throw createError({ statusCode: 400, statusMessage: 'installationId is required' })
11 }
12
13 const handle = handleRaw.trim()
14 const installationId = installationIdRaw
15
16 const client = await useOAuthClient()
17
18 // Round-trip the installation id via OAuth `state`. The library wraps and
19 // signs `state` itself (PKCE + state CSRF protection are handled internally),
20 // so this is safe to use as an opaque link key.
21 const url = await client.authorize(handle, {
22 state: installationId,
23 scope: 'atproto transition:generic',
24 })
25
26 await sendRedirect(event, url.toString(), 302)
27})