Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/danielroe/roe.dev. This is the code and content for my personal website, built in Nuxt. roe.dev
Something went wrong. Try again.
TypeScript
12345678910111213141516171819202122232425import type { H3Event } from 'nitro/h3'import { Agent } from '@atproto/api'
import { clearAdminSessionCookie, getAdminSessionCookie, getOauthClient } from './oauth'
/** Restore the admin's OAuth session into an `@atproto/api` Agent. */export async function requireAdminAgent (event: H3Event): Promise<{ agent: Agent, did: string }> { const sess = await getAdminSessionCookie(event) const did = sess.data.did if (!did) { throw createError({ status: 401, message: 'Not signed in.' }) }
const client = getOauthClient(event) try { const oauthSession = await client.restore(did) return { agent: new Agent(oauthSession), did } } catch (err) { console.warn('[admin] OAuth restore failed:', err instanceof Error ? err.message : err) await clearAdminSessionCookie(event) throw createError({ status: 401, message: 'Session expired. Please sign in again.' }) }}