mirror your GitHub repos to tangled.org automatically
1

Configure Feed

Select the types of activity you want to include in your feed.

1import { userIdentity } from '~~/server/db/schema' 2import { generateAndPublishKey } from '~~/server/utils/tangled-pubkey' 3 4export default defineEventHandler(async event => { 5 const url = getRequestURL(event) 6 const params = url.searchParams 7 8 const client = await useOAuthClient() 9 const { session, state } = await client.callback(params) 10 11 const installationId = state ? Number(state) : NaN 12 if (!Number.isFinite(installationId)) { 13 throw createError({ statusCode: 400, statusMessage: 'invalid state (missing installation id)' }) 14 } 15 16 const db = useDb() 17 await db.insert(userIdentity).values({ 18 did: session.did, 19 handle: null, // resolved separately; we don't have it from the session blob 20 installationId, 21 updatedAt: new Date(), 22 }).onConflictDoUpdate({ 23 target: userIdentity.did, 24 set: { installationId, updatedAt: new Date() }, 25 }) 26 27 // Generate and publish the SSH key inline: it's one ed25519 keygen + one 28 // PDS write, well under the function timeout, and lets us land users on the 29 // dashboard already enrolled. Rotation is a separate dashboard action that 30 // goes via the queue. 31 await generateAndPublishKey({ 32 oauthSession: session, 33 installationId, 34 }) 35 36 await sendRedirect(event, '/dashboard', 302) 37})