Skip to main content

wavekat_platform_client/
me.rs

1//! `/api/me` — the typed shape of the signed-in user.
2//!
3//! Public because every consumer needs it: the CLI prints it after
4//! `wk login`/`wk me`, and the desktop daemon shows the same fields in
5//! its Platform settings page. Keeping the struct here (and re-exported
6//! from the crate root) means consumers don't redefine it.
7
8use serde::Deserialize;
9
10use crate::client::Client;
11use crate::error::Result;
12
13/// The signed-in user, as returned by `GET /api/me`.
14#[derive(Debug, Clone, Deserialize)]
15pub struct Me {
16    pub id: i64,
17    pub login: String,
18    pub name: Option<String>,
19    pub email: Option<String>,
20    pub role: String,
21}
22
23impl Client {
24    /// Fetch the signed-in user from `/api/me`. The canonical way to
25    /// verify a freshly-minted token is reachable.
26    pub async fn whoami(&self) -> Result<Me> {
27        self.get_json("/api/me").await
28    }
29
30    /// Revoke the bearer token this client is using. After this returns
31    /// successfully, the same token will start producing 401s — drop the
32    /// `Client` (and clear whatever storage held the token).
33    pub async fn revoke_current_token(&self) -> Result<()> {
34        self.post_empty("/api/auth/cli/tokens/revoke-current").await
35    }
36}