Skip to content

Commit 5c6274a

Browse files
authored
delete token from db (#902)
1 parent 287c11c commit 5c6274a

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,
@@ -428,33 +429,31 @@ impl Cli {
428429
if let Some(secret_store) = secret_store {
429430
if let Ok(database) = database().map_err(|err| error!(?err, "failed to open database")) {
430431
// check builderid token flow
431-
if let Ok(token) = BuilderIdToken::load(&secret_store, false).await {
432+
if let Ok(Some(token)) = BuilderIdToken::load(&secret_store, false).await {
432433
// Save the device registration. This is required for token refresh to succeed.
433-
if let Some(token) = token.as_ref() {
434-
let region = token.region.clone().map_or(OIDC_BUILDER_ID_REGION, Region::new);
435-
match DeviceRegistration::load_from_secret_store(&secret_store, &region).await {
436-
Ok(Some(reg)) => match serde_json::to_string(&reg) {
437-
Ok(reg) => {
438-
database
439-
.set_auth_value("codewhisperer:odic:device-registration", reg)
440-
.map_err(|err| error!(?err, "failed to write device registration to auth db"))
441-
.ok();
442-
},
443-
Err(err) => error!(?err, "failed to serialize the device registration"),
434+
let region = token.region.clone().map_or(OIDC_BUILDER_ID_REGION, Region::new);
435+
match DeviceRegistration::load_from_secret_store(&secret_store, &region).await {
436+
Ok(Some(reg)) => match serde_json::to_string(&reg) {
437+
Ok(reg) => {
438+
database
439+
.set_auth_value(DeviceRegistration::SECRET_KEY, reg)
440+
.map_err(|err| error!(?err, "failed to write device registration to auth db"))
441+
.ok();
444442
},
445-
Ok(None) => {
446-
warn!(?token, "no device registration found for token");
447-
},
448-
Err(err) => {
449-
error!(?err, "failed to load device registration");
450-
},
451-
}
443+
Err(err) => error!(?err, "failed to serialize the device registration"),
444+
},
445+
Ok(None) => {
446+
warn!(?token, "no device registration found for token");
447+
},
448+
Err(err) => {
449+
error!(?err, "failed to load device registration");
450+
},
452451
}
453452

454453
// Next, save the token.
455454
if let Ok(token) = serde_json::to_string(&token) {
456455
database
457-
.set_auth_value("codewhisperer:odic:token", token)
456+
.set_auth_value(BuilderIdToken::SECRET_KEY, token)
458457
.map_err(|err| error!(?err, "failed to write credentials to auth db"))
459458
.ok();
460459
}
@@ -465,7 +464,7 @@ impl Cli {
465464
Ok(Some(social)) => {
466465
if let Ok(social_json) = serde_json::to_string(&social) {
467466
database
468-
.set_auth_value("codewhisperer:social:token", social_json)
467+
.set_auth_value(SocialToken::SECRET_KEY, social_json)
469468
.map_err(|err| error!(?err, "failed to write social token to auth db"))
470469
.ok();
471470
}

0 commit comments

Comments
 (0)