Skip to content

Commit 82bcc87

Browse files
xuyushun441-sysos-zhuangclaude
authored
fix(console): claim the device code before approve/deny (#1676)
better-auth's device-authorization plugin requires the verifying session to claim the code (GET /device?user_code=…) before approve/deny — both returned 400 'not been claimed by a verifying session' otherwise, so the approval button silently failed (found in the bind-v2 E2E; pre-existing, not introduced by #1673). Co-authored-by: Jack Zhuang <277994282+os-zhuang@users.noreply.github.com> Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
1 parent c5935a7 commit 82bcc87

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

.changeset/device-approve-claim.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@object-ui/console": patch
3+
---
4+
5+
DeviceAuthPage claims the device code (GET /device?user_code=…) before approve/deny — better-auth's device-authorization plugin rejects both with 400 "not been claimed by a verifying session" otherwise, so approval silently failed.

apps/console/src/pages/auth/DeviceAuthPage.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,21 @@ export function DeviceAuthPage() {
143143
);
144144
}
145145

146+
// better-auth's device-authorization plugin requires the verifying
147+
// session to CLAIM the code (GET /device?user_code=…) before it will
148+
// accept approve/deny — without it both return 400 "not been claimed
149+
// by a verifying session". Idempotent, so claim right before acting.
150+
const claimDevice = async () => {
151+
await fetch(`${AUTH_BASE}/device?user_code=${encodeURIComponent(code)}`, {
152+
credentials: 'include',
153+
}).catch(() => { /* approve below surfaces the real error */ });
154+
};
155+
146156
const handleApprove = async () => {
147157
setError('');
148158
setSubmitting(true);
149159
try {
160+
await claimDevice();
150161
const res = await fetch(`${AUTH_BASE}/device/approve`, {
151162
method: 'POST',
152163
headers: { 'Content-Type': 'application/json' },
@@ -186,6 +197,7 @@ export function DeviceAuthPage() {
186197
setError('');
187198
setDenying(true);
188199
try {
200+
await claimDevice();
189201
await fetch(`${AUTH_BASE}/device/deny`, {
190202
method: 'POST',
191203
headers: { 'Content-Type': 'application/json' },

0 commit comments

Comments
 (0)