mirror of
https://github.com/perstarkse/minne.git
synced 2026-03-20 16:44:12 +01:00
feat signout and reactivity
This commit is contained in:
@@ -13,6 +13,7 @@ use crate::{
|
||||
|
||||
page_data!(IndexData, "index.html", {
|
||||
queue_length: u32,
|
||||
user: Option<User>
|
||||
});
|
||||
|
||||
pub async fn index_handler(
|
||||
@@ -21,11 +22,12 @@ pub async fn index_handler(
|
||||
) -> Result<Html<String>, ApiError> {
|
||||
info!("Displaying index page");
|
||||
|
||||
info!("{:?}", auth.current_user);
|
||||
|
||||
let queue_length = state.rabbitmq_consumer.get_queue_length().await?;
|
||||
|
||||
let data = IndexData { queue_length };
|
||||
let data = IndexData {
|
||||
queue_length,
|
||||
user: auth.current_user,
|
||||
};
|
||||
|
||||
let output = render_template(IndexData::template_name(), data, state.templates)?;
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ use minijinja_autoreload::AutoReloader;
|
||||
pub mod index;
|
||||
pub mod search_result;
|
||||
pub mod signin;
|
||||
pub mod signout;
|
||||
pub mod signup;
|
||||
|
||||
pub trait PageData {
|
||||
|
||||
18
src/server/routes/html/signout.rs
Normal file
18
src/server/routes/html/signout.rs
Normal file
@@ -0,0 +1,18 @@
|
||||
use axum::response::{IntoResponse, Redirect};
|
||||
use axum_session_auth::AuthSession;
|
||||
use axum_session_surreal::SessionSurrealPool;
|
||||
use surrealdb::{engine::any::Any, Surreal};
|
||||
|
||||
use crate::{error::ApiError, storage::types::user::User};
|
||||
|
||||
pub async fn sign_out_user(
|
||||
auth: AuthSession<User, String, SessionSurrealPool<Any>, Surreal<Any>>,
|
||||
) -> Result<impl IntoResponse, ApiError> {
|
||||
if !auth.is_authenticated() {
|
||||
return Ok(Redirect::to("/").into_response());
|
||||
}
|
||||
|
||||
auth.logout_user();
|
||||
|
||||
Ok(Redirect::to("/").into_response())
|
||||
}
|
||||
Reference in New Issue
Block a user