@@ -5,6 +5,11 @@ import { saveConfig } from "../helpers/config";
55import { getWebAppUrl } from "../helpers/urls" ;
66import { clearScreen } from "../helpers/prompt" ;
77
8+ // We're using Axios here because there's a bug
9+ // where the fetch API in Bun isn't passing the body
10+ // through redirects correctly
11+ import axios from "axios" ;
12+
813export function registerLogin ( program : Command ) {
914 program
1015 . command ( "login" )
@@ -47,53 +52,52 @@ async function createSession({
4752} : {
4853 validation : string ;
4954} ) {
50- const response = await fetch ( await getWebAppUrl ( "cli_session_create" ) , {
51- method : "POST" ,
52- headers : {
53- "Content-Type" : "application/json" ,
54- } ,
55- body : JSON . stringify ( { validation } ) ,
56- } ) ;
57- if ( ! response . ok ) {
58- console . error ( "Response not ok" , response . status , response . statusText ) ;
59- return null ;
60- }
55+ const url = await getWebAppUrl ( "cli_session_create" ) ;
6156
62- const body = ( await response . json ( ) ) as {
63- url : string ;
64- token : string ;
65- } ;
57+ try {
58+ const response = await axios . post (
59+ url ,
60+ { validation } ,
61+ {
62+ headers : {
63+ "Content-Type" : "application/json" ,
64+ } ,
65+ maxRedirects : 5 ,
66+ } ,
67+ ) ;
6668
67- return body ;
69+ return response . data as {
70+ url : string ;
71+ token : string ;
72+ } ;
73+ } catch ( error ) {
74+ console . error ( "Error creating session:" , error ) ;
75+ return null ;
76+ }
6877}
6978
7079async function getSession ( {
7180 token,
7281} : {
7382 token : string ;
7483} ) {
75- const response = await fetch (
76- await getWebAppUrl ( "cli_session_get" , {
77- token,
78- } ) ,
79- {
80- method : "GET" ,
84+ try {
85+ const url = await getWebAppUrl ( "cli_session_get" , { token } ) ;
86+ const response = await axios . get ( url , {
8187 headers : {
8288 "Content-Type" : "application/json" ,
8389 } ,
84- } ,
85- ) ;
86- if ( ! response . ok ) {
87- console . error ( "Response not ok" , response . status , response . statusText ) ;
90+ } ) ;
91+
92+ return response . data as {
93+ validation ?: string ;
94+ token ?: string ;
95+ } ;
96+ } catch ( error ) {
97+ console . error ( "Error getting session:" , error ) ;
8898 process . exit ( 1 ) ;
8999 return null ;
90100 }
91-
92- const body = ( await response . json ( ) ) as {
93- validation ?: string ;
94- token ?: string ;
95- } ;
96- return body ;
97101}
98102
99103function generateValidationString ( ) {
0 commit comments