Skip to content

Commit d1665e3

Browse files
authored
fix: don't change teams when JWT expires (#158)
1 parent bdd6184 commit d1665e3

1 file changed

Lines changed: 12 additions & 10 deletions

File tree

crates/config/src/session.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,11 @@ impl Session {
217217
jwt: session_response.token.jwt.clone(),
218218
};
219219

220-
// Remember the current active team's JWT if there is one
221-
let active_team_jwt = self.active_team.as_ref().map(|team| team.token.jwt.clone());
220+
// Remember current active team after refresh
221+
let active_team_aid = self
222+
.active_team
223+
.as_ref()
224+
.and_then(|team| extract_aid_from_jwt(&team.token.jwt));
222225

223226
// Update teams
224227
self.teams = session_response
@@ -240,15 +243,14 @@ impl Session {
240243
})
241244
.collect();
242245

243-
// Try to restore the active team based on the JWT
244-
let jwt_match_found = if let Some(jwt) = active_team_jwt {
245-
self.set_active_team_by_jwt(&jwt)
246-
} else {
247-
false
248-
};
246+
// Try to restore the active team by account ID (JWT changes after refresh)
247+
let found_active_team = active_team_aid
248+
.as_ref()
249+
.map(|aid| self.set_active_team_by_aid(aid))
250+
.unwrap_or(false);
249251

250-
// If no active team was set by JWT, fall back to a personal team
251-
if !jwt_match_found && self.active_team.is_none() {
252+
// Fall back to personal team if previous active team not found
253+
if !found_active_team {
252254
// Find a team with team_type="personal"
253255
if let Some(personal_team) = self.teams.iter().find(|team| team.team_type == "personal")
254256
{

0 commit comments

Comments
 (0)