Skip to content

Commit

Permalink
Only call register after github login (#929)
Browse files Browse the repository at this point in the history
  • Loading branch information
rsdy committed Sep 4, 2023
1 parent a590647 commit 083954d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 16 deletions.
16 changes: 0 additions & 16 deletions server/bleep/src/webserver/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,6 @@ pub(super) async fn get(
.and_then(|login| app.user_profiles.read(login, |_, v| v.clone()))
.unwrap_or_default();

if let Some(username) = user.login() {
app.with_analytics(|analytics| {
use rudderanalytics::message::{Identify, Message};
analytics.send(Message::Identify(Identify {
user_id: Some(tracking_id.clone()),
traits: Some(serde_json::json!({
"org_name": app.org_name(),
"device_id": analytics.device_id(),
"is_self_serve": app.env.is_cloud_instance(),
"github_username": username.to_string(),
})),
..Default::default()
}));
});
}

json(ConfigResponse {
analytics_data_plane: app.config.analytics_data_plane.clone(),
analytics_key_fe: app.config.analytics_key_fe.clone(),
Expand Down
31 changes: 31 additions & 0 deletions server/bleep/src/webserver/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,37 @@ async fn poll_for_oauth_token(code: String, app: Application) {

debug!("acquired credentials");
app.credentials.set_github(github::Auth::OAuth(auth));
let username = app
.credentials
.github()
.unwrap()
.client()
.unwrap()
.current()
.user()
.await
.unwrap()
.login;

let tracking_id = app
.analytics
.as_ref()
.map(|a| a.tracking_id(Some(&username)))
.unwrap_or_default();

app.with_analytics(|analytics| {
use rudderanalytics::message::{Identify, Message};
analytics.send(Message::Identify(Identify {
user_id: Some(tracking_id.clone()),
traits: Some(serde_json::json!({
"org_name": app.org_name(),
"device_id": analytics.device_id(),
"is_self_serve": app.env.is_cloud_instance(),
"github_username": username,
})),
..Default::default()
}));
});

if let Err(err) = app.credentials.store() {
error!(?err, "failed to save credentials to disk");
Expand Down

0 comments on commit 083954d

Please sign in to comment.