1- use std:: sync:: { Arc , RwLock } ;
1+ use std:: sync:: { Arc , OnceLock , RwLock } ;
22
33use bitwarden_crypto:: KeyStore ;
44#[ cfg( any( feature = "internal" , feature = "secrets" ) ) ]
@@ -13,6 +13,7 @@ use super::login_method::ServiceAccountLoginMethod;
1313use crate :: {
1414 auth:: renew:: renew_token,
1515 client:: { encryption_settings:: EncryptionSettings , login_method:: LoginMethod } ,
16+ error:: UserIdAlreadySetError ,
1617 key_management:: KeyIds ,
1718 DeviceType ,
1819} ;
@@ -44,6 +45,7 @@ pub(crate) struct Tokens {
4445
4546#[ derive( Debug ) ]
4647pub struct InternalClient {
48+ pub ( crate ) user_id : OnceLock < Uuid > ,
4749 pub ( crate ) tokens : RwLock < Tokens > ,
4850 pub ( crate ) login_method : RwLock < Option < Arc < LoginMethod > > > ,
4951
@@ -172,6 +174,14 @@ impl InternalClient {
172174 & self . key_store
173175 }
174176
177+ pub fn init_user_id ( & self , user_id : Uuid ) -> Result < ( ) , UserIdAlreadySetError > {
178+ self . user_id . set ( user_id) . map_err ( |_| UserIdAlreadySetError )
179+ }
180+
181+ pub fn get_user_id ( & self ) -> Option < Uuid > {
182+ self . user_id . get ( ) . copied ( )
183+ }
184+
175185 #[ cfg( feature = "internal" ) ]
176186 pub ( crate ) fn initialize_user_crypto_master_key (
177187 & self ,
0 commit comments