use axum::{
response::{Html, IntoResponse, Response},
routing::get,
};
use micron::{config, Config};
#[tokio::main]
async fn main() {
let config = Config {
domain: "127.0.0.1:8000".to_string(),
registration: config::Registration {
enabled: true,
oauth: true,
..Default::default()
},
oauth: config::Oauth {
enabled: true,
github: config::OauthEntry {
enabled: true,
client_id: "c31f7946cd7ccf47d3d2".to_string(),
client_secret: "8a1b86e774f42222d26ed1c08e970f3dad58c167".to_string(),
},
..Default::default()
},
..Default::default()
};
let mut router = micron::axum::Router::new().route("/", get(home));
router = micron::axum::router(router, &config);
micron::axum::start(router, config).await.expect("failed")
}
async fn home(user: Option<micron::axum::extract::User>) -> Response {
if let Some(user) = user {
Html(format!(
"welcome {}! | credits: {} | <a href=\"/logout\">log out</a>",
user.email, user.credits.available
))
.into_response()
} else {
Html("landing page | <a href=\"/login/github\">log in with github</a>").into_response()
}
}