main
rs 46 lines 1.24 KB
Raw
1 use serde::{Deserialize, Serialize};
2 use uuid::Uuid;
3
4 #[derive(Clone, Debug, Deserialize, Serialize)]
5 /// Contains information for identifying the end-user.
6 ///
7 /// Different [`UserID`]'s might correspond to the same end-user;
8 /// we use the [`UserID`] to translate to a canonical user.
9 pub struct UserID {
10 /// Randomly generated ID for the user, which exists whether or not they are logged in.
11 pub anonymous_id: String,
12
13 /// The client's access token. This is either:
14 /// * A short-lived firebase ID token (not refresh token).
15 /// * A Warp API key.
16 ///
17 /// [`Some`] iff we know who the end-user is (i.e. they're logged in).
18 #[serde(rename = "firebase_id_token")]
19 pub access_token: Option<String>,
20 }
21
22 impl Default for UserID {
23 fn default() -> Self {
24 Self {
25 anonymous_id: Uuid::new_v4().to_string(),
26 access_token: None,
27 }
28 }
29 }
30
31 /// A newtype for a firebase uid.
32 #[derive(Debug, Serialize, Deserialize, Eq, PartialEq, Clone)]
33 #[serde(transparent)]
34 pub struct FirebaseUid(String);
35
36 impl From<String> for FirebaseUid {
37 fn from(value: String) -> Self {
38 Self(value)
39 }
40 }
41
42 impl From<FirebaseUid> for String {
43 fn from(value: FirebaseUid) -> Self {
44 value.0
45 }
46 }