import { Image } from "expo-image"; import { Alert, Button, StyleSheet, TextInput } from "react-native"; import { Agent } from "@atproto/api"; import { TID } from "@atproto/common-web"; import { HelloWave } from "@/components/HelloWave"; import ParallaxScrollView from "@/components/ParallaxScrollView"; import { ThemedText } from "@/components/ThemedText"; import { ThemedView } from "@/components/ThemedView"; import { useState } from "react"; import { ExpoOAuthClient } from "expo-atproto-auth"; import { OAuthSession } from "@atproto/oauth-client"; import { WebBrowserResultType } from "expo-web-browser"; const client = new ExpoOAuthClient({ clientMetadata: { client_id: "https://hailey.at/oauth-client-metadata.json", client_name: "Hailey's Atproto App", client_uri: "https://hailey.at", redirect_uris: ["at.hailey:/auth/callback"], scope: "atproto transition:generic", token_endpoint_auth_method: "none", response_types: ["code"], grant_types: ["authorization_code", "refresh_token"], application_type: "native", dpop_bound_access_tokens: true, }, handleResolver: "https://bsky.social", }); export default function HomeScreen() { const [handle, setHandle] = useState(""); const [agent, setAgent] = useState(null); const [isProcessing, setIsProcessing] = useState(false); const [postTitle, setPostTitle] = useState(""); const [postText, setPostText] = useState(""); const [name, setName] = useState(); const onSignInPress = async () => { let res: | { status: WebBrowserResultType; } | { status: "error"; error: unknown; } | { status: "success"; session: OAuthSession; }; setIsProcessing(true); try { res = await client.signIn(handle); } catch (e) { console.log(e); return; } finally { setIsProcessing(false); } if (res.status === "error") { Alert.alert("Authentication Error", (res.error as any).toString()); } else if (res.status === "success") { const newAgent = new Agent(res.session); setAgent(newAgent); const pres = await newAgent.getProfile({ actor: newAgent.did! }); setName(pres.data.displayName); } }; const onCreatePost = async () => { const entry: WhtwndBlogEntryRecord = { $type: "com.whtwnd.blog.entry", createdAt: new Date().toISOString(), title: postTitle, content: postText, }; setIsProcessing(true); try { await agent!.com.atproto.repo.createRecord({ repo: agent!.did!, collection: "com.whtwnd.blog.entry", record: entry, rkey: TID.nextStr(), }); } catch (e) { console.log(e); } finally { setIsProcessing(false); } Alert.alert("Post Created!", "Your post has been published!!!"); }; return ( } > Welcome! {agent === null ? ( <> Sign into your account to get started!