Scrapboard.org client

fix: oauth and add error messages

+20 -7
+7 -4
src/lib/hooks/useAuth.tsx
··· 14 14 type OAuthSession, 15 15 } from "@atproto/oauth-client-browser"; 16 16 import { Agent } from "@atproto/api"; 17 + import { th } from "zod/v4/locales"; 17 18 18 19 type AuthContextType = { 19 20 session: OAuthSession | null; ··· 34 35 useEffect(() => { 35 36 const initClient = async () => { 36 37 const isDev = process.env.NODE_ENV === "development"; 37 - const handleResolver = new AtprotoDohHandleResolver({ 38 - dohEndpoint: "https://dns.google/resolve", 39 - }); 40 38 41 39 const c = isDev 42 40 ? new BrowserOAuthClient({ 43 - handleResolver, 41 + handleResolver: "https://bsky.social", 44 42 clientMetadata: { 45 43 client_name: "Statusphere React App", 46 44 client_id: `http://localhost?scope=${encodeURI( ··· 109 107 }); 110 108 } catch (e) { 111 109 console.warn("Login aborted or failed", e); 110 + throw new Error( 111 + `Login failed: ${e instanceof Error ? e.message : "Unknown error"}` 112 + ); 112 113 } 113 114 }, 114 115 [client] ··· 119 120 client.revoke(session.sub); 120 121 setSession(null); 121 122 setAgent(null); 123 + // refresh page 124 + window.location.reload(); 122 125 } 123 126 }, [client, session]); 124 127
+13 -3
src/nav/navbar.tsx
··· 144 144 const { login } = useAuth(); 145 145 const [handle, setHandle] = useState(""); 146 146 const [isLoading, setLoading] = useState(false); 147 + const [error, setError] = useState(""); 147 148 return ( 148 149 <Dialog> 149 150 <DialogTrigger> ··· 163 164 /> 164 165 </DialogDescription> 165 166 </DialogHeader> 166 - <DialogFooter> 167 + <DialogFooter className="justify-between flex w-full"> 168 + {error && <div className="text-red-500 text-sm mb-2">{error}</div>} 167 169 <Button 168 - onClick={() => { 170 + onClick={async () => { 169 171 setLoading(true); 170 - login(handle); 172 + try { 173 + await login(handle); 174 + } catch (e) { 175 + setError( 176 + e instanceof Error ? e.message : "Unknown error occurred" 177 + ); 178 + } finally { 179 + setLoading(false); 180 + } 171 181 }} 172 182 disabled={!handle} 173 183 className="cursor-pointer"