Store device_id in session
The device_id is needed by the client, but otherwise inaccessible (unless provided to the server by the client). This is analogous to how the user_id is currently stored for guests, but will probably be more often used. The device_id is needed to implement e2e encryption.
This commit is contained in:
		
							parent
							
								
									c8bc590cba
								
							
						
					
					
						commit
						eb92b86ce4
					
				| @ -114,7 +114,7 @@ where | ||||
|             }, | ||||
|         ) | ||||
|         .map(move |response| { | ||||
|             let session = Session::new(response.access_token, response.user_id); | ||||
|             let session = Session::new(response.access_token, response.user_id, response.device_id); | ||||
|             *data.session.borrow_mut() = Some(session.clone()); | ||||
| 
 | ||||
|             session | ||||
| @ -142,7 +142,7 @@ where | ||||
|             }, | ||||
|         ) | ||||
|         .map(move |response| { | ||||
|             let session = Session::new(response.access_token, response.user_id); | ||||
|             let session = Session::new(response.access_token, response.user_id, response.device_id); | ||||
|             *data.session.borrow_mut() = Some(session.clone()); | ||||
| 
 | ||||
|             session | ||||
| @ -179,7 +179,7 @@ where | ||||
|             }, | ||||
|         ) | ||||
|         .map(move |response| { | ||||
|             let session = Session::new(response.access_token, response.user_id); | ||||
|             let session = Session::new(response.access_token, response.user_id, response.device_id); | ||||
|             *data.session.borrow_mut() = Some(session.clone()); | ||||
| 
 | ||||
|             session | ||||
|  | ||||
| @ -7,14 +7,17 @@ pub struct Session { | ||||
|     access_token: String, | ||||
|     /// The user the access token was issued for.
 | ||||
|     user_id: UserId, | ||||
|     /// The ID of the client device
 | ||||
|     device_id: String, | ||||
| } | ||||
| 
 | ||||
| impl Session { | ||||
|     /// Create a new user session from an access token and a user ID.
 | ||||
|     pub fn new(access_token: String, user_id: UserId) -> Self { | ||||
|     pub fn new(access_token: String, user_id: UserId, device_id: String) -> Self { | ||||
|         Session { | ||||
|             access_token, | ||||
|             user_id, | ||||
|             device_id, | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
| @ -27,4 +30,9 @@ impl Session { | ||||
|     pub fn user_id(&self) -> &UserId { | ||||
|         &self.user_id | ||||
|     } | ||||
| 
 | ||||
|     /// Get ID of the device the session belongs to.
 | ||||
|     pub fn device_id(&self) -> &str { | ||||
|         &self.device_id | ||||
|     } | ||||
| } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user