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 /// Opaque platform user id. A UUID string since wavekat-platform
17 /// switched `users.id` off integer surrogate keys (which leaked the
18 /// signup count). Treat as an opaque token — never parse or compare
19 /// numerically.
20 pub id: String,
21 pub login: String,
22 pub name: Option<String>,
23 pub email: Option<String>,
24 pub role: String,
25}
26
27impl Client {
28 /// Fetch the signed-in user from `/api/me`. The canonical way to
29 /// verify a freshly-minted token is reachable.
30 pub async fn whoami(&self) -> Result<Me> {
31 self.get_json("/api/me").await
32 }
33
34 /// Revoke the bearer token this client is using. After this returns
35 /// successfully, the same token will start producing 401s — drop the
36 /// `Client` (and clear whatever storage held the token).
37 pub async fn revoke_current_token(&self) -> Result<()> {
38 self.post_empty("/api/auth/cli/tokens/revoke-current").await
39 }
40}