Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
fairingrey committed Feb 19, 2022
1 parent 16b6e52 commit 562487b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 25 deletions.
37 changes: 19 additions & 18 deletions src/handlers/login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,25 +122,26 @@ pub(crate) async fn logout(
TypedHeader(cookie): TypedHeader<Cookie>,
state: Extension<Arc<State>>,
) -> Result<Response<Body>, MixiniError> {
if let Some(sessid) = cookie.get(SESSION_COOKIE_NAME) {
let prefixed_key = format!("{}{}", SESSION_KEY_PREFIX, sessid);
state.redis_manager.to_owned().del(&prefixed_key).await?;
Ok(Response::builder()
match cookie.get(SESSION_COOKIE_NAME) {
Some(sessid) => {
let prefixed_key = format!("{}{}", SESSION_KEY_PREFIX, sessid);
state.redis_manager.to_owned().del(&prefixed_key).await?;
Ok(Response::builder()
.status(StatusCode::OK)
.header(
header::SET_COOKIE,
format!(
"{cname}=expired; Secure; HttpOnly; Domain={domain}; Max-Age=-1",
cname = SESSION_COOKIE_NAME,
domain = *DOMAIN,
),
)
.body(Body::empty())
.unwrap())
}
None => Ok(Response::builder()
.status(StatusCode::OK)
.header(
header::SET_COOKIE,
format!(
"{cname}=expired; Secure; HttpOnly; Domain={domain}; Max-Age=-1",
cname = SESSION_COOKIE_NAME,
domain = *DOMAIN,
),
)
.body(Body::empty())
.unwrap())
} else {
Ok(Response::builder()
.status(StatusCode::OK)
.body(Body::empty())
.unwrap())
.unwrap()),
}
}
9 changes: 2 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub(crate) mod utils;
pub(crate) const DEV_BUILD: bool = cfg!(debug_assertions);

#[tokio::main]
async fn main() -> Result<(), anyhow::Result<()>> {
async fn main() -> anyhow::Result<()> {
if DEV_BUILD {
dotenv::dotenv().ok();
} else {
Expand All @@ -28,10 +28,5 @@ async fn main() -> Result<(), anyhow::Result<()>> {
std::env::set_var("RUST_LOG", "mixini_server=debug,tower_http=debug")
}
tracing_subscriber::fmt::init();

if let Err(err) = server::run().await {
eprintln!("Error: {}", err);
std::process::exit(1);
}
Ok(())
server::run().await
}

0 comments on commit 562487b

Please sign in to comment.