Skip to content

Commit 98f0bfd

Browse files
committed
[vibe] auth token should be in cache, not config
1 parent 3769dd0 commit 98f0bfd

4 files changed

Lines changed: 11 additions & 11 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ A Rust CLI tool to extract and display workouts from the WeightXReps.net website
77
## Features
88

99
- Authenticates using email and password from `credentials.txt` (email first line, password second)
10+
- Authenticates and caches JWT token in `$XDG_CACHE_HOME/wxrust/token` (or `~/.cache/wxrust/token`)
1011
- Retrieves individual workouts or lists of workout dates
1112
- Formats output with colors matching the website editor
1213
- Supports detailed views, summaries, and date filtering

src/api.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use async_trait::async_trait;
2-
use reqwest::Client;
32
use serde::de::DeserializeOwned;
43
use serde_json;
54
use ansi_term::Colour;
@@ -63,15 +62,15 @@ pub struct DataAccess<'a, C: ApiClient> {
6362

6463
#[derive(Clone)]
6564
pub struct ReqwestClient {
66-
client: Client,
65+
client: reqwest::Client,
6766
verbose: bool,
6867
user_info: OnceCell<crate::models::User>,
6968
}
7069

7170
impl ReqwestClient {
7271
pub fn new_with_verbose(verbose: bool) -> Self {
7372
ReqwestClient {
74-
client: Client::new(),
73+
client: reqwest::Client::new(),
7574
verbose,
7675
user_info: OnceCell::new(),
7776
}
@@ -171,7 +170,7 @@ pub async fn graphql_request<T: DeserializeOwned + 'static, C: ApiClient>(client
171170

172171
#[cfg_attr(tarpaulin, ignore)]
173172
#[allow(dead_code)]
174-
pub async fn workout_request(client: &Client, token: &str, request: &WorkoutRequest) -> Result<WorkoutResponse, Box<dyn std::error::Error>> {
173+
pub async fn workout_request(client: &reqwest::Client, token: &str, request: &WorkoutRequest) -> Result<WorkoutResponse, Box<dyn std::error::Error>> {
175174
let response = client
176175
.post("https://weightxreps.net/api/graphql")
177176
.header("Authorization", format!("Bearer {}", token))

src/main.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,12 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
145145

146146
unsafe { std::env::set_var("WXRUST_COLOR", &args.color); }
147147

148-
let token_path = if let Some(config_dir) = dirs::config_dir() {
149-
config_dir.join("wxrust").join("token").to_string_lossy().to_string()
150-
} else {
151-
// Fallback
152-
let home = std::env::var("HOME").unwrap_or(".".to_string());
153-
format!("{}/.config/wxrust/token", home)
148+
let token_path = match workouts::get_cache_base_dir() {
149+
Ok(dir) => dir.join("token").to_string_lossy().to_string(),
150+
Err(_) => {
151+
let home = std::env::var("HOME").unwrap_or(".".to_string());
152+
format!("{}/.cache/wxrust/token", home)
153+
}
154154
};
155155

156156
// Set credentials path if provided

src/workouts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ fn limit_and_sort_dates(mut dates: Vec<String>, count: u32, reverse: bool) -> Ve
3030
dates
3131
}
3232

33-
fn get_cache_base_dir() -> Result<PathBuf, String> {
33+
pub fn get_cache_base_dir() -> Result<PathBuf, String> {
3434
let cache_dir = if let Ok(dir) = std::env::var("XDG_CACHE_HOME") {
3535
if !dir.is_empty() {
3636
PathBuf::from(dir)

0 commit comments

Comments
 (0)