Something went wrong. Try again.
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667import type { Agent as AgentType } from "@atproto/api";
const CLIENT_METADATA = { client_id: "https://vertedinde.tngl.io/client-metadata.json" as `https://${string}`, client_name: "Walkabout", redirect_uris: ["io.tngl.vertedinde:/callback" as `${string}://${string}`], scope: "atproto transition:generic", grant_types: ["authorization_code" as const, "refresh_token" as const], response_types: ["code" as const], dpop_bound_access_tokens: true, token_endpoint_auth_method: "none" as const, application_type: "native" as const,};
async function getClient() { const { ExpoOAuthClient } = await import("@atproto/oauth-client-expo"); return new ExpoOAuthClient({ clientMetadata: CLIENT_METADATA, handleResolver: "https://bsky.social", });}
export async function signIn(handle: string): Promise<{ agent: AgentType; did: string; handle: string; avatar?: string;}> { const client = await getClient(); const session = await client.signIn(handle); const { Agent } = await import("@atproto/api"); const agent = new Agent(session); const did = session.did;
const profile = await agent.getProfile({ actor: did });
return { agent, did, handle: profile.data.handle, avatar: profile.data.avatar, };}
export async function restoreSession(did: string): Promise<{ agent: AgentType; did: string; handle: string; avatar?: string;} | null> { try { const client = await getClient(); const session = await client.restore(did); const { Agent } = await import("@atproto/api"); const agent = new Agent(session); const profile = await agent.getProfile({ actor: did }); return { agent, did, handle: profile.data.handle, }; } catch { return null; }}