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
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950/** * Build-time airspace clients, for the Nuxt modules that run before the Nitro * runtime exists and so can't use `server/utils/airspace.ts`. * * Identity comes from `runtimeConfig.atproto`, populated by `modules/atproto`, */import { createAirspace, passwordSession } from 'airspace'import type { AnyCollection, Identity } from 'airspace'import { useRuntimeConfig } from 'nuxt/kit'
import { collections } from '../../shared/collections.ts'
function identity () { const config = useRuntimeConfig() const did = config.atproto.did const service = config.public.atproto.service if (!did || !service) { throw new Error( 'runtimeConfig.atproto.did / public.atproto.service are not set; the build-time atproto module did not resolve them from social.networks.bluesky.identifier.', ) } return { did, service } as { did: Identity['did'], service: string }}
let readOnly: ReturnType<typeof createAirspace<typeof collections>> | null = null
/** Unauthenticated reads against our own PDS. */export function useBuildAirspace () { return readOnly ??= createAirspace({ identity: identity(), collections })}
/** * A client that can write, for the sync providers. Needs * `NUXT_ATPROTO_PASSWORD`; the PDS and DID are already resolved. */export async function useBuildAirspaceWithSession<const C extends Record<string, AnyCollection>> (used: C): Promise<ReturnType<typeof createAirspace<C>>>export async function useBuildAirspaceWithSession (): Promise<ReturnType<typeof createAirspace<typeof collections>>>export async function useBuildAirspaceWithSession (used: Record<string, AnyCollection> = collections) { const { handle, password } = useRuntimeConfig().atproto const { service } = identity() if (!handle || !password) { throw new Error(`atproto credentials are not configured (missing ${!handle ? 'social.networks.bluesky.identifier' : 'NUXT_ATPROTO_PASSWORD'}).`) } return createAirspace({ identity: identity(), collections: used, session: await passwordSession({ service, identifier: handle, password }), })}