tangled
alpha
login
or
join now
bunware.org
/
pin.to.it
6
fork
atom
Scrapboard.org client
6
fork
atom
overview
issues
pulls
pipelines
fix: oauth and add error messages
bunware.org
7 months ago
6b808105
3d3de3fc
+20
-7
2 changed files
expand all
collapse all
unified
split
src
lib
hooks
useAuth.tsx
nav
navbar.tsx
+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
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
37
-
const handleResolver = new AtprotoDohHandleResolver({
38
38
-
dohEndpoint: "https://dns.google/resolve",
39
39
-
});
40
38
41
39
const c = isDev
42
40
? new BrowserOAuthClient({
43
43
-
handleResolver,
41
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
110
+
throw new Error(
111
111
+
`Login failed: ${e instanceof Error ? e.message : "Unknown error"}`
112
112
+
);
112
113
}
113
114
},
114
115
[client]
···
119
120
client.revoke(session.sub);
120
121
setSession(null);
121
122
setAgent(null);
123
123
+
// refresh page
124
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
147
+
const [error, setError] = useState("");
147
148
return (
148
149
<Dialog>
149
150
<DialogTrigger>
···
163
164
/>
164
165
</DialogDescription>
165
166
</DialogHeader>
166
166
-
<DialogFooter>
167
167
+
<DialogFooter className="justify-between flex w-full">
168
168
+
{error && <div className="text-red-500 text-sm mb-2">{error}</div>}
167
169
<Button
168
168
-
onClick={() => {
170
170
+
onClick={async () => {
169
171
setLoading(true);
170
170
-
login(handle);
172
172
+
try {
173
173
+
await login(handle);
174
174
+
} catch (e) {
175
175
+
setError(
176
176
+
e instanceof Error ? e.message : "Unknown error occurred"
177
177
+
);
178
178
+
} finally {
179
179
+
setLoading(false);
180
180
+
}
171
181
}}
172
182
disabled={!handle}
173
183
className="cursor-pointer"