mirror of
https://github.com/perstarkse/minne.git
synced 2026-03-19 07:54:29 +01:00
tailwindcss + wip auth
This commit is contained in:
@@ -1,23 +1,33 @@
|
||||
use axum::{
|
||||
extract::DefaultBodyLimit,
|
||||
http::Method,
|
||||
routing::{get, post},
|
||||
Router,
|
||||
};
|
||||
use axum_session::{SessionConfig, SessionLayer, SessionStore};
|
||||
use axum_session_auth::{Auth, AuthConfig, AuthSession, AuthSessionLayer, Rights};
|
||||
use axum_session_surreal::SessionSurrealPool;
|
||||
use std::sync::Arc;
|
||||
use surrealdb::{engine::any::Any, Surreal};
|
||||
use tera::Tera;
|
||||
use tower_http::services::ServeDir;
|
||||
use tracing::info;
|
||||
use tracing_subscriber::{fmt, prelude::*, EnvFilter};
|
||||
use zettle_db::{
|
||||
rabbitmq::{consumer::RabbitMQConsumer, publisher::RabbitMQProducer, RabbitMQConfig},
|
||||
server::{
|
||||
routes::{
|
||||
file::upload_handler, index::index_handler, ingress::ingress_handler,
|
||||
query::query_handler, queue_length::queue_length_handler,
|
||||
auth::{show_signup_form, signup_handler},
|
||||
file::upload_handler,
|
||||
index::index_handler,
|
||||
ingress::ingress_handler,
|
||||
query::query_handler,
|
||||
queue_length::queue_length_handler,
|
||||
search_result::search_result_handler,
|
||||
},
|
||||
AppState,
|
||||
},
|
||||
storage::db::SurrealDbClient,
|
||||
storage::{db::SurrealDbClient, types::user::User},
|
||||
};
|
||||
|
||||
#[tokio::main(flavor = "multi_thread", worker_threads = 2)]
|
||||
@@ -44,11 +54,32 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
tera: Arc::new(Tera::new("src/server/templates/**/*.html").unwrap()),
|
||||
openai_client: Arc::new(async_openai::Client::new()),
|
||||
};
|
||||
// app_state.surreal_db_client.query("DELETE user").await?;
|
||||
|
||||
// setup_auth(&app_state.surreal_db_client).await?;
|
||||
|
||||
let session_config = SessionConfig::default()
|
||||
.with_table_name("test_session_table")
|
||||
.with_secure(false);
|
||||
let auth_config = AuthConfig::<String>::default();
|
||||
|
||||
let session_store: SessionStore<SessionSurrealPool<Any>> = SessionStore::new(
|
||||
Some(app_state.surreal_db_client.client.clone().into()),
|
||||
session_config,
|
||||
)
|
||||
.await?;
|
||||
|
||||
// Create Axum router
|
||||
let app = Router::new()
|
||||
.nest("/api/v1", api_routes_v1())
|
||||
.nest("", html_routes())
|
||||
.nest(
|
||||
"/",
|
||||
html_routes(
|
||||
session_store,
|
||||
auth_config,
|
||||
app_state.surreal_db_client.client.clone(),
|
||||
),
|
||||
)
|
||||
.with_state(app_state);
|
||||
|
||||
tracing::info!("Listening on 0.0.0.0:3000");
|
||||
@@ -72,9 +103,34 @@ fn api_routes_v1() -> Router<AppState> {
|
||||
}
|
||||
|
||||
/// Router for HTML endpoints
|
||||
fn html_routes() -> Router<AppState> {
|
||||
///
|
||||
fn html_routes(
|
||||
session_store: SessionStore<SessionSurrealPool<Any>>,
|
||||
auth_config: AuthConfig<String>,
|
||||
db_client: Surreal<Any>,
|
||||
) -> Router<AppState> {
|
||||
Router::new()
|
||||
.route("/", get(index_handler))
|
||||
.route("/search", get(search_result_handler))
|
||||
.route("/signup", get(show_signup_form).post(signup_handler))
|
||||
.nest_service("/assets", ServeDir::new("src/server/assets"))
|
||||
.layer(
|
||||
AuthSessionLayer::<User, String, SessionSurrealPool<Any>, Surreal<Any>>::new(Some(
|
||||
db_client,
|
||||
))
|
||||
.with_config(auth_config),
|
||||
)
|
||||
.layer(SessionLayer::new(session_store))
|
||||
}
|
||||
|
||||
// async fn setup_auth(db: &SurrealDbClient) -> Result<(), Box<dyn std::error::Error>> {
|
||||
// db.query(
|
||||
// "DEFINE TABLE user SCHEMALESS;
|
||||
// DEFINE INDEX unique_name ON TABLE user FIELDS email UNIQUE;
|
||||
// DEFINE ACCESS account ON DATABASE TYPE RECORD
|
||||
// SIGNUP ( CREATE user SET email = $email, password = crypto::argon2::generate($password), anonymous = false, user_id = $user_id)
|
||||
// SIGNIN ( SELECT * FROM user WHERE email = $email AND crypto::argon2::compare(password, $password) );",
|
||||
// )
|
||||
// .await?;
|
||||
// Ok(())
|
||||
// }
|
||||
|
||||
Reference in New Issue
Block a user