diff --git a/admin_frontend/src/config.rs b/admin_frontend/src/config.rs new file mode 100644 index 00000000..ab1c325c --- /dev/null +++ b/admin_frontend/src/config.rs @@ -0,0 +1,26 @@ +use tracing::warn; + +#[derive(Debug, Clone)] +pub struct Config { + pub redis_url: String, + pub gotrue_url: String, +} + +impl Config { + pub fn from_env() -> Self { + Config { + redis_url: get_or_default("ADMIN_FRONTEND_REDIS_URL", "redis://localhost:6379"), + gotrue_url: get_or_default("ADMIN_FRONTEND_GOTRUE_URL", "http://localhost:9999"), + } + } +} + +fn get_or_default(key: &str, default: &str) -> String { + std::env::var(key).unwrap_or_else(|e| { + warn!( + "failed to get env var: {}, err: {}, using default: {}", + key, e, default + ); + default.to_string() + }) +} diff --git a/admin_frontend/src/main.rs b/admin_frontend/src/main.rs index 5d30738a..48a81bfa 100644 --- a/admin_frontend/src/main.rs +++ b/admin_frontend/src/main.rs @@ -1,3 +1,4 @@ +mod config; mod error; mod models; mod response; @@ -16,6 +17,8 @@ use tower_http::{ }; use tracing::info; +use crate::config::Config; + #[tokio::main] async fn main() { // load from .env @@ -27,16 +30,23 @@ async fn main() { .with_env_filter(tracing_subscriber::EnvFilter::from_default_env()) .init(); - let gotrue_client = gotrue::api::Client::new( - reqwest::Client::new(), - &std::env::var("GOTRUE_URL").unwrap_or("http://gotrue:9999".to_string()), - ); - let redis_client = - redis::Client::open(std::env::var("REDIS_URL").unwrap_or("redis://redis:6379".to_string())) - .unwrap() - .get_tokio_connection_manager() - .await - .unwrap(); + let config = Config::from_env(); + info!("config loaded: {:?}", &config); + + let gotrue_client = gotrue::api::Client::new(reqwest::Client::new(), &config.gotrue_url); + gotrue_client + .health() + .await + .expect("gotrue health check failed"); + info!("Gotrue client initialized."); + + let redis_client = redis::Client::open(config.redis_url) + .expect("failed to create redis client") + .get_tokio_connection_manager() + .await + .expect("failed to get redis connection manager"); + info!("Redis client initialized."); + let session_store = session::SessionStorage::new(redis_client); let state = AppState { @@ -64,9 +74,13 @@ async fn main() { .nest_service("/web-api", web_api_router) .nest_service("/assets", ServeDir::new("assets")); - let listener = TcpListener::bind("0.0.0.0:3000").await.unwrap(); + let listener = TcpListener::bind("0.0.0.0:3000") + .await + .expect("failed to bind to port"); info!("listening on: {:?}", listener); - axum::serve(listener, app).await.unwrap(); + axum::serve(listener, app) + .await + .expect("failed to run server"); } #[derive(Clone)] diff --git a/admin_frontend/src/web_api.rs b/admin_frontend/src/web_api.rs index 3071c467..fad51267 100644 --- a/admin_frontend/src/web_api.rs +++ b/admin_frontend/src/web_api.rs @@ -376,16 +376,14 @@ async fn send_magic_link( State(state): State, email: &str, ) -> Result, WebApiError<'static>> { - Ok( - state - .gotrue_client - .magic_link(&MagicLinkParams { - email: email.to_owned(), - ..Default::default() - }) - .await? - .into(), - ) + state + .gotrue_client + .magic_link(&MagicLinkParams { + email: email.to_owned(), + ..Default::default() + }) + .await?; + Ok(WebApiResponse::<()>::from_str("Magic Link Sent".into())) } fn get_base_url(header_map: &HeaderMap) -> String { diff --git a/admin_frontend/templates/components/admin_sso_create.html b/admin_frontend/templates/components/admin_sso_create.html index 206b66df..dfa789d7 100644 --- a/admin_frontend/templates/components/admin_sso_create.html +++ b/admin_frontend/templates/components/admin_sso_create.html @@ -1,6 +1,6 @@

Please enter the following information to create new SSO

-
+ diff --git a/admin_frontend/templates/components/admin_user_details.html b/admin_frontend/templates/components/admin_user_details.html index 3b58ec4c..d0cd5db6 100644 --- a/admin_frontend/templates/components/admin_user_details.html +++ b/admin_frontend/templates/components/admin_user_details.html @@ -2,7 +2,7 @@ {% include "user_details.html" %}
- +
Email
diff --git a/admin_frontend/templates/components/change_password.html b/admin_frontend/templates/components/change_password.html index 560154d0..204d6910 100644 --- a/admin_frontend/templates/components/change_password.html +++ b/admin_frontend/templates/components/change_password.html @@ -1,6 +1,6 @@

Password Change

- +
Set Password:
diff --git a/admin_frontend/templates/components/create_user.html b/admin_frontend/templates/components/create_user.html index 5df3efb9..e8fc6a6c 100644 --- a/admin_frontend/templates/components/create_user.html +++ b/admin_frontend/templates/components/create_user.html @@ -1,6 +1,6 @@

Please enter the following information to create a new user

- +
New Password:
diff --git a/admin_frontend/templates/components/invite.html b/admin_frontend/templates/components/invite.html index 125deff1..6a41bd79 100644 --- a/admin_frontend/templates/components/invite.html +++ b/admin_frontend/templates/components/invite.html @@ -1,6 +1,6 @@

Please enter the following email invite a new user

- +
Email:
diff --git a/admin_frontend/templates/layouts/base.html b/admin_frontend/templates/layouts/base.html index ef8177cc..3c438a55 100644 --- a/admin_frontend/templates/layouts/base.html +++ b/admin_frontend/templates/layouts/base.html @@ -19,6 +19,7 @@
{% block content %}{% endblock %}
+ diff --git a/admin_frontend/templates/pages/login.html b/admin_frontend/templates/pages/login.html index c925261a..4722299e 100644 --- a/admin_frontend/templates/pages/login.html +++ b/admin_frontend/templates/pages/login.html @@ -58,6 +58,7 @@
Email: