mirror your GitHub repos to tangled.org automatically
1import { requireSession, switchAccount } from '~~/server/utils/server-session'
2
3export default defineEventHandler(async event => {
4 await requireSession(event)
5 const body = await readBody<{ did?: unknown }>(event)
6 const did = typeof body?.did === 'string' ? body.did : null
7 if (!did) {
8 throw createError({ statusCode: 400, statusMessage: 'missing did' })
9 }
10
11 const switched = await switchAccount(event, did)
12 if (!switched) {
13 throw createError({ statusCode: 404, statusMessage: 'account not signed in on this device' })
14 }
15
16 return { ok: true, active: did }
17})