Skip to content

Commit

Permalink
/users/me endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
banocean committed Jan 15, 2024
1 parent d69a5b4 commit ceade23
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/server/routes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ mod interactions;
#[cfg(feature = "api")]
mod login;

#[cfg(feature = "api")]
mod users {
pub mod me;
}

pub fn get_all_routes(
discord_http: Arc<Client>,
context: Arc<Context>,
Expand All @@ -33,7 +38,9 @@ pub fn get_all_routes(
};

#[cfg(feature = "api")]
let filter = filter.or(login::login(authenticator, sessions));
let filter = filter
.or(login::login(authenticator.to_owned(), sessions.to_owned()))
.or(users::me::run(authenticator.to_owned(), sessions.to_owned()))

filter
}
16 changes: 16 additions & 0 deletions src/server/routes/users/me.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use std::sync::Arc;
use warp::Filter;
use crate::response_type;
use crate::server::session::{Authenticator, AuthorizationInformation, authorize_user, Sessions};

pub fn run(
authenticator: Arc<Authenticator>,
sessions: Arc<Sessions>
) -> response_type!() {
warp::get()
.and(warp::path!("users" / "me"))
.and(authorize_user(authenticator, sessions))
.map(|info: Arc<AuthorizationInformation>| {
warp::reply::json(&info.user)
})
}

0 comments on commit ceade23

Please sign in to comment.