summaryrefslogtreecommitdiff
path: root/src/ui
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/routes/me.rs32
-rw-r--r--src/ui/routes/mod.rs2
2 files changed, 34 insertions, 0 deletions
diff --git a/src/ui/routes/me.rs b/src/ui/routes/me.rs
new file mode 100644
index 0000000..f1f118f
--- /dev/null
+++ b/src/ui/routes/me.rs
@@ -0,0 +1,32 @@
+pub mod get {
+ use axum::response::{self, IntoResponse, Redirect};
+
+ use crate::{
+ error::Internal,
+ token::extract::Identity,
+ ui::assets::{Asset, Assets},
+ };
+
+ pub async fn handler(identity: Option<Identity>) -> Result<Asset, Error> {
+ let _ = identity.ok_or(Error::NotLoggedIn)?;
+
+ Assets::index().map_err(Error::Internal)
+ }
+
+ #[derive(Debug, thiserror::Error)]
+ pub enum Error {
+ #[error("not logged in")]
+ NotLoggedIn,
+ #[error("{0}")]
+ Internal(Internal),
+ }
+
+ impl IntoResponse for Error {
+ fn into_response(self) -> response::Response {
+ match self {
+ Self::NotLoggedIn => Redirect::temporary("/login").into_response(),
+ Self::Internal(error) => error.into_response(),
+ }
+ }
+ }
+}
diff --git a/src/ui/routes/mod.rs b/src/ui/routes/mod.rs
index 72d9a4a..48b3f90 100644
--- a/src/ui/routes/mod.rs
+++ b/src/ui/routes/mod.rs
@@ -6,6 +6,7 @@ mod ch;
mod get;
mod invite;
mod login;
+mod me;
mod path;
mod setup;
@@ -16,6 +17,7 @@ pub fn router(app: &App) -> Router<App> {
.route("/setup", get(setup::get::handler)),
Router::new()
.route("/", get(get::handler))
+ .route("/me", get(me::get::handler))
.route("/login", get(login::get::handler))
.route("/ch/:channel", get(ch::channel::get::handler))
.route("/invite/:invite", get(invite::invite::get::handler))