- add: Refresh Session call to actually refresh the cache session.
This commit is contained in:
@@ -7,7 +7,7 @@ use crate::auth::{
|
||||
use crate::common::Empty;
|
||||
use crate::database_client::{DatabaseClient, DatabaseClientTrait};
|
||||
use crate::session::session_service_client::SessionServiceClient;
|
||||
use crate::session::{GetSessionRequest};
|
||||
use crate::session::{GetSessionRequest, RefreshSessionRequest};
|
||||
use crate::users::{hash_password, verify_user};
|
||||
use chrono::{Duration, Utc};
|
||||
use rand::Rng;
|
||||
@@ -78,7 +78,7 @@ impl AuthService for MyAuthService {
|
||||
.session_client
|
||||
.as_ref()
|
||||
.clone()
|
||||
.get_session(GetSessionRequest {
|
||||
.refresh_session(RefreshSessionRequest {
|
||||
session_id: req.session_id,
|
||||
})
|
||||
.await;
|
||||
@@ -87,7 +87,7 @@ impl AuthService for MyAuthService {
|
||||
Ok(res) => {
|
||||
let res = res.into_inner();
|
||||
debug!("Session valid: {:?}", res);
|
||||
Ok(Response::new(RefreshSessionResponse { valid: true }))
|
||||
Ok(Response::new(RefreshSessionResponse { valid: res.valid }))
|
||||
}
|
||||
Err(_) => {
|
||||
debug!("Unable to refresh session");
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::session::{session_service_client::SessionServiceClient, GetSessionRequest, GetSessionResponse};
|
||||
use crate::session::{session_service_client::SessionServiceClient, GetSessionRequest, GetSessionResponse, RefreshSessionRequest, RefreshSessionResponse};
|
||||
use async_trait::async_trait;
|
||||
use chrono::{DateTime, Utc};
|
||||
use std::error::Error;
|
||||
@@ -11,6 +11,10 @@ pub trait SessionClientTrait: Sized {
|
||||
&mut self,
|
||||
session_id: String,
|
||||
) -> Result<GetSessionResponse, Box<dyn std::error::Error>>;
|
||||
async fn refresh_session(
|
||||
&mut self,
|
||||
session_id: String,
|
||||
) -> Result<RefreshSessionResponse, Box<dyn std::error::Error>>;
|
||||
}
|
||||
#[derive(Clone)]
|
||||
pub struct SessionClient {
|
||||
@@ -31,4 +35,11 @@ impl SessionClientTrait for SessionClient {
|
||||
let response = self.client.get_session(request).await?;
|
||||
Ok(response.into_inner())
|
||||
}
|
||||
async fn refresh_session(&mut self, session_id: String) -> Result<RefreshSessionResponse, Box<dyn Error>> {
|
||||
let request = tonic::Request::new(RefreshSessionRequest {
|
||||
session_id,
|
||||
});
|
||||
let response = self.client.refresh_session(request).await?;
|
||||
Ok(response.into_inner())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user