@@ -33,7 +33,7 @@ pub fn copy_token(token: &str) {
3333 }
3434}
3535
36- pub fn login ( config : & mut Config , token : Option < String > ) {
36+ pub fn login ( config : & mut Config , token : Option < String > , github_token : Option < String > ) {
3737 if let Some ( token) = token {
3838 config. index_token = Some ( token) ;
3939 config. save ( ) ;
@@ -50,6 +50,25 @@ pub fn login(config: &mut Config, token: Option<String>) {
5050
5151 let client = reqwest:: blocking:: Client :: new ( ) ;
5252
53+ if let Some ( github_token) = github_token {
54+ let response = client
55+ . post ( index:: get_index_url ( "/v1/login/github/token" , config) )
56+ . header ( USER_AGENT , "GeodeCli" )
57+ . json ( & json ! ( { "token" : github_token } ) )
58+ . send ( )
59+ . nice_unwrap ( "Unable to connect to Geode Index" ) ;
60+
61+ let parsed: ApiResponse < String > = match response. status ( ) . as_u16 ( ) {
62+ 400 => fatal ! ( "Invalid Github Token" ) ,
63+ 200 => response. json ( ) . nice_unwrap ( "Unable to parse login response" ) ,
64+ _ => fatal ! ( "Unable to connect to Geode Index" ) ,
65+ } ;
66+
67+ config. index_token = Some ( parsed. payload ) ;
68+ config. save ( ) ;
69+ done ! ( "Successfully logged in via Github token" ) ;
70+ }
71+
5372 let response: reqwest:: blocking:: Response = client
5473 . post ( index:: get_index_url ( "/v1/login/github" , config) )
5574 . header ( USER_AGENT , "GeodeCli" )
0 commit comments