Skip to content

Commit

Permalink
fix(backend): Github Oauth
Browse files Browse the repository at this point in the history
  • Loading branch information
Brayan-724 committed Sep 14, 2024
1 parent 766e39a commit 2bba6f3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
5 changes: 3 additions & 2 deletions crates/backend/src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ pub async fn github_callback(req: worker::Request, ctx: RouterContext) -> Worker
let GithubUser {
id: user_id,
email: user_email,
name: user_name,
..
} = github::get_user(token).await?;

Expand All @@ -63,7 +64,7 @@ pub async fn github_callback(req: worker::Request, ctx: RouterContext) -> Worker
D1EntityUpdate::update_query(
ExternalUpdate {
id: external_user.id,
email: Some(user_email),
email: Some(user_email.unwrap_or(user_name)),
token: Some(external_token.clone()),
},
&db,
Expand All @@ -75,7 +76,7 @@ pub async fn github_callback(req: worker::Request, ctx: RouterContext) -> Worker
ExternalCreate {
kind: "Github".to_owned(),
external_id: user_id.to_string(),
email: user_email,
email: user_email.unwrap_or(user_name),
token: external_token.clone(),
},
&db,
Expand Down
5 changes: 2 additions & 3 deletions crates/backend/src/auth/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ async fn res_worker_to_oauth2(res: worker::HttpResponse) -> oauth2::HttpResponse
pub struct GithubUser {
pub id: u64,
// pub avatar_url: String,
// pub name: String,
pub email: String,
pub name: String,
pub email: Option<String>,
}

/// https://docs.github.com/en/rest/users/emails?apiVersion=2022-11-28#list-email-addresses-for-the-authenticated-user
Expand Down Expand Up @@ -207,7 +207,6 @@ pub async fn get_user(token: GithubToken) -> Result<GithubUser, worker::Response

let res = res.text().await.map_err(IntoResponse::into_response)?;

worker::console_log!("[REMOVE] Test response: {res}"); // XXX: Remove this
let user = serde_json::from_str::<GithubUser>(&res).map_err(IntoResponse::into_response)?;

Ok(user)
Expand Down

0 comments on commit 2bba6f3

Please sign in to comment.