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.
1234567891011121314151617181920212223242526import type { H3Event } from 'h3'import { Client } from '@atproto/lex'import type { DidString } from '@atproto/lex'
import { clearAdminSessionCookie, getAdminSessionCookie, getOauthClient } from './oauth'
/** Restore the admin's OAuth session into an `@atproto/lex` Client. */export async function requireAdminClient (event: H3Event): Promise<{ client: Client, did: DidString }> { const sess = await getAdminSessionCookie(event) const did = sess.data.did if (!did) { throw createError({ statusCode: 401, statusMessage: 'Not signed in.' }) }
const oauthClient = getOauthClient(event) try { const oauthSession = await oauthClient.restore(did) return { client: new Client(oauthSession), did: oauthSession.did } } catch (err) { console.warn('[admin] OAuth restore failed:', err instanceof Error ? err.message : err) await clearAdminSessionCookie(event) throw createError({ statusCode: 401, statusMessage: 'Session expired. Please sign in again.' }) }}