11import { jsonError , jsonSuccess } from "@/lib/api/response" ;
22import { enforceCliDeviceDecisionRateLimit } from "@/lib/api/rate-limit" ;
3- import { handleRouteError , requireSessionOrThrow } from "@/lib/api/route-helpers" ;
3+ import { requireSessionOrThrow } from "@/lib/api/route-helpers" ;
44import { parseJsonBodyWithSchema } from "@/lib/api/validation" ;
5- import { postToDeviceAuthEndpoint , parseDeviceAuthError } from "@/lib/cli/device-auth" ;
5+ import { auth } from "@/lib/auth-server" ;
6+ import {
7+ parseDeviceAuthApiError ,
8+ resolveDeviceAuthApiErrorStatus ,
9+ } from "@/lib/cli/device-auth" ;
610import { cliDeviceDecisionSchema } from "@/lib/cli/schemas" ;
711
812export async function POST ( request : Request ) {
@@ -17,30 +21,18 @@ export async function POST(request: Request) {
1721 }
1822
1923 const input = await parseJsonBodyWithSchema ( request , cliDeviceDecisionSchema ) ;
20- const response = await postToDeviceAuthEndpoint ( {
21- request,
22- path : "/device/approve" ,
24+ const response = await auth . api . deviceApprove ( {
25+ headers : request . headers ,
2326 body : {
2427 userCode : input . userCode ,
2528 } ,
2629 } ) ;
2730
28- if ( response . status >= 400 ) {
29- return jsonError (
30- parseDeviceAuthError ( response . payload , "Unable to approve device code." ) ,
31- {
32- code : "CLI_DEVICE_AUTH_APPROVE_ERROR" ,
33- status : response . status ,
34- } ,
35- ) ;
36- }
37-
38- return jsonSuccess ( response . payload ) ;
31+ return jsonSuccess ( response ) ;
3932 } catch ( error ) {
40- return handleRouteError ( error , {
41- message : "Unable to approve device code." ,
33+ return jsonError ( parseDeviceAuthApiError ( error , "Unable to approve device code." ) , {
4234 code : "CLI_DEVICE_AUTH_APPROVE_ERROR" ,
43- status : 400 ,
35+ status : resolveDeviceAuthApiErrorStatus ( error , 400 ) ,
4436 } ) ;
4537 }
4638}
0 commit comments