Skip to content

Commit afd1396

Browse files
committed
delete token from db
1 parent 74a746f commit afd1396

File tree

2 files changed

+27
-21
lines changed

2 files changed

+27
-21
lines changed

crates/fig_auth/src/session.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use aws_smithy_runtime_api::client::identity::{
88
IdentityFuture,
99
ResolveIdentity,
1010
};
11+
use fig_settings::sqlite::database;
1112
use tracing::{
1213
info,
1314
warn,
@@ -73,6 +74,12 @@ pub async fn logout() -> Result<()> {
7374
secret_store.delete(SocialToken::SECRET_KEY),
7475
);
7576

77+
if let Ok(db) = database() {
78+
let _ = db.unset_auth_value(BuilderIdToken::SECRET_KEY);
79+
let _ = db.unset_auth_value(DeviceRegistration::SECRET_KEY);
80+
let _ = db.unset_auth_value(SocialToken::SECRET_KEY);
81+
}
82+
7683
let profile_res = fig_settings::state::remove_value("api.codewhisperer.profile");
7784

7885
builder_res?;

crates/q_cli/src/cli/mod.rs

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ use fig_auth::consts::OIDC_BUILDER_ID_REGION;
5353
use fig_auth::is_logged_in;
5454
use fig_auth::pkce::Region;
5555
use fig_auth::secret_store::SecretStore;
56+
use fig_auth::social::SocialToken;
5657
use fig_ipc::local::open_ui_element;
5758
use fig_log::{
5859
LogArgs,
@@ -418,33 +419,31 @@ impl Cli {
418419
if let Some(secret_store) = secret_store {
419420
if let Ok(database) = database().map_err(|err| error!(?err, "failed to open database")) {
420421
// check builderid token flow
421-
if let Ok(token) = BuilderIdToken::load(&secret_store, false).await {
422+
if let Ok(Some(token)) = BuilderIdToken::load(&secret_store, false).await {
422423
// Save the device registration. This is required for token refresh to succeed.
423-
if let Some(token) = token.as_ref() {
424-
let region = token.region.clone().map_or(OIDC_BUILDER_ID_REGION, Region::new);
425-
match DeviceRegistration::load_from_secret_store(&secret_store, &region).await {
426-
Ok(Some(reg)) => match serde_json::to_string(&reg) {
427-
Ok(reg) => {
428-
database
429-
.set_auth_value("codewhisperer:odic:device-registration", reg)
430-
.map_err(|err| error!(?err, "failed to write device registration to auth db"))
431-
.ok();
432-
},
433-
Err(err) => error!(?err, "failed to serialize the device registration"),
424+
let region = token.region.clone().map_or(OIDC_BUILDER_ID_REGION, Region::new);
425+
match DeviceRegistration::load_from_secret_store(&secret_store, &region).await {
426+
Ok(Some(reg)) => match serde_json::to_string(&reg) {
427+
Ok(reg) => {
428+
database
429+
.set_auth_value(DeviceRegistration::SECRET_KEY, reg)
430+
.map_err(|err| error!(?err, "failed to write device registration to auth db"))
431+
.ok();
434432
},
435-
Ok(None) => {
436-
warn!(?token, "no device registration found for token");
437-
},
438-
Err(err) => {
439-
error!(?err, "failed to load device registration");
440-
},
441-
}
433+
Err(err) => error!(?err, "failed to serialize the device registration"),
434+
},
435+
Ok(None) => {
436+
warn!(?token, "no device registration found for token");
437+
},
438+
Err(err) => {
439+
error!(?err, "failed to load device registration");
440+
},
442441
}
443442

444443
// Next, save the token.
445444
if let Ok(token) = serde_json::to_string(&token) {
446445
database
447-
.set_auth_value("codewhisperer:odic:token", token)
446+
.set_auth_value(BuilderIdToken::SECRET_KEY, token)
448447
.map_err(|err| error!(?err, "failed to write credentials to auth db"))
449448
.ok();
450449
}
@@ -455,7 +454,7 @@ impl Cli {
455454
Ok(Some(social)) => {
456455
if let Ok(social_json) = serde_json::to_string(&social) {
457456
database
458-
.set_auth_value("codewhisperer:social:token", social_json)
457+
.set_auth_value(SocialToken::SECRET_KEY, social_json)
459458
.map_err(|err| error!(?err, "failed to write social token to auth db"))
460459
.ok();
461460
}

0 commit comments

Comments
 (0)