Skip to content

Commit a9852eb

Browse files
gold-ak47claude
andcommitted
fix: PAT login fails when stale OAuth fields exist
is_oauth() now checks for non-empty session_token instead of just Some(). PAT login clears session_token, figma_refresh_token, and figma_token_expires_at so subsequent API calls use the correct X-Figma-Token header. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent b88e285 commit a9852eb

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

src/commands/login.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ async fn run_token_login(token: &str) -> Result<()> {
8989
config.figma_token = Some(token.to_string());
9090
config.user_email = Some(me.email);
9191
config.user_name = Some(me.handle);
92+
// Clear any stale OAuth fields so is_oauth() returns false
93+
config.session_token = None;
94+
config.figma_refresh_token = None;
95+
config.figma_token_expires_at = None;
9296
}
9397
Err(e) => {
9498
println!("{}", format!("Failed: {e}").red());
@@ -326,6 +330,10 @@ async fn run_pat_login() -> Result<()> {
326330
config.figma_token = Some(token);
327331
config.user_email = Some(me.email);
328332
config.user_name = Some(me.handle);
333+
// Clear any stale OAuth fields so is_oauth() returns false
334+
config.session_token = None;
335+
config.figma_refresh_token = None;
336+
config.figma_token_expires_at = None;
329337
}
330338
Err(e) => {
331339
println!("{}", format!("Failed: {e}").red());

src/config.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,10 @@ impl GlobalConfig {
6868
/// Returns true if the stored token came from OAuth (device flow login)
6969
/// vs a Personal Access Token (--pat or --figma-token).
7070
pub fn is_oauth(&self) -> bool {
71-
self.session_token.is_some()
71+
self.session_token
72+
.as_deref()
73+
.map(|s| !s.is_empty())
74+
.unwrap_or(false)
7275
}
7376

7477
/// Create a FigmaClient with the right auth header (OAuth Bearer vs PAT).

0 commit comments

Comments
 (0)