1- use actix_web:: { dev:: ConnectionInfo , post, web, Responder } ;
1+ use actix_web:: http:: StatusCode ;
2+ use actix_web:: { dev:: ConnectionInfo , post, web, HttpResponse , Responder } ;
23use serde:: Deserialize ;
34use sqlx:: { types:: ipnetwork:: IpNetwork , Acquire } ;
45use uuid:: Uuid ;
@@ -125,7 +126,7 @@ pub async fn github_web_callback(
125126 error : "" . to_string ( ) ,
126127 payload : TokensResponse {
127128 access_token : token. to_string ( ) ,
128- refresh_token : Some ( refresh. to_string ( ) ) ,
129+ refresh_token : refresh. to_string ( ) ,
129130 } ,
130131 } ) )
131132}
@@ -212,13 +213,20 @@ pub async fn poll_github_login(
212213
213214 tx. commit ( ) . await . or ( Err ( ApiError :: TransactionError ) ) ?;
214215
215- Ok ( web:: Json ( ApiResponse {
216- error : "" . to_string ( ) ,
217- payload : TokensResponse {
218- access_token : token. to_string ( ) ,
219- refresh_token : refresh. map ( |r| r. to_string ( ) ) ,
220- } ,
221- } ) )
216+ if expiry {
217+ Ok ( HttpResponse :: build ( StatusCode :: OK ) . json ( ApiResponse {
218+ error : "" . to_string ( ) ,
219+ payload : TokensResponse {
220+ access_token : token. to_string ( ) ,
221+ refresh_token : refresh. unwrap ( ) . to_string ( ) ,
222+ } ,
223+ } ) )
224+ } else {
225+ Ok ( HttpResponse :: build ( StatusCode :: OK ) . json ( ApiResponse {
226+ error : "" . to_string ( ) ,
227+ payload : token. to_string ( ) ,
228+ } ) )
229+ }
222230}
223231
224232#[ post( "v1/login/github/token" ) ]
@@ -232,11 +240,12 @@ pub async fn github_token_login(
232240 ) ;
233241
234242 let user = match client. get_user ( & json. token ) . await {
235- Err ( _) => client. get_installation ( & json. token ) . await . map_err ( |_|
236- ApiError :: BadRequest ( format ! ( "Invalid access token: {}" , json. token) )
237- ) ?,
243+ Err ( _) => client
244+ . get_installation ( & json. token )
245+ . await
246+ . map_err ( |_| ApiError :: BadRequest ( format ! ( "Invalid access token: {}" , json. token) ) ) ?,
238247
239- Ok ( u) => u
248+ Ok ( u) => u,
240249 } ;
241250
242251 let mut pool = data
0 commit comments