add ingore_auth feature on backend

This commit is contained in:
appflowy
2021-10-05 19:32:58 +08:00
parent 155a526d04
commit ef4ee320f7
7 changed files with 16 additions and 17 deletions

View File

@ -92,6 +92,7 @@ path = "src/main.rs"
[features]
flowy_test = []
ignore_auth = []
[dev-dependencies]
parking_lot = "0.11"

View File

@ -49,9 +49,7 @@ where
type Error = Error;
type Future = LocalBoxFuture<'static, Result<Self::Response, Self::Error>>;
fn poll_ready(&self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
self.service.poll_ready(cx)
}
fn poll_ready(&self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> { self.service.poll_ready(cx) }
fn call(&self, req: ServiceRequest) -> Self::Future {
let mut authenticate_pass: bool = false;
@ -68,9 +66,15 @@ where
let result: Result<LoggedUser, ServerError> = header.try_into();
match result {
Ok(logged_user) => {
authenticate_pass = AUTHORIZED_USERS.is_authorized(&logged_user);
// Update user timestamp
AUTHORIZED_USERS.store_auth(logged_user, true);
if cfg!(feature = "ignore_auth") {
authenticate_pass = true;
AUTHORIZED_USERS.store_auth(logged_user, true);
} else {
authenticate_pass = AUTHORIZED_USERS.is_authorized(&logged_user);
if authenticate_pass {
AUTHORIZED_USERS.store_auth(logged_user, true);
}
}
},
Err(e) => log::error!("{:?}", e),
}

View File

@ -15,11 +15,7 @@ pub struct LoggedUser {
}
impl std::convert::From<Claim> for LoggedUser {
fn from(c: Claim) -> Self {
Self {
user_id: c.user_id(),
}
}
fn from(c: Claim) -> Self { Self { user_id: c.user_id() } }
}
impl LoggedUser {
@ -93,7 +89,6 @@ impl AuthorizedUsers {
AuthStatus::Authorized(last_time) => {
let current_time = Utc::now();
let days = (current_time - last_time).num_days();
log::debug!("user active {} from now", days);
days < EXPIRED_DURATION_DAYS
},
AuthStatus::NotAuthorized => {