summaryrefslogtreecommitdiffstats
path: root/crates/auth/src/state.rs
diff options
context:
space:
mode:
authorrtkay123 <dev@kanjala.com>2025-07-23 13:39:40 +0200
committerrtkay123 <dev@kanjala.com>2025-07-23 13:39:40 +0200
commit089efa225cc0a4e7be12608129ddbff28d11f320 (patch)
treed5d27ba5f5056c7a539365fd314e6d7ce7529523 /crates/auth/src/state.rs
parent0a48abb0f0d4752b639fb89dd2db32a3db0eebb8 (diff)
downloadsellershut-089efa225cc0a4e7be12608129ddbff28d11f320.tar.bz2
sellershut-089efa225cc0a4e7be12608129ddbff28d11f320.zip
feat(auth): discord oauth
Diffstat (limited to 'crates/auth/src/state.rs')
-rw-r--r--crates/auth/src/state.rs45
1 files changed, 45 insertions, 0 deletions
diff --git a/crates/auth/src/state.rs b/crates/auth/src/state.rs
new file mode 100644
index 0000000..5a483c9
--- /dev/null
+++ b/crates/auth/src/state.rs
@@ -0,0 +1,45 @@
+use std::{ops::Deref, sync::Arc};
+
+use stack_up::{Configuration, Services};
+
+use crate::{
+ client::{OauthClient, discord::discord_client},
+ cnfg::LocalConfig,
+ error::AppError,
+};
+
+#[derive(Clone)]
+pub struct AppHandle(Arc<AppState>);
+
+impl Deref for AppHandle {
+ type Target = Arc<AppState>;
+
+ fn deref(&self) -> &Self::Target {
+ &self.0
+ }
+}
+
+pub struct AppState {
+ pub services: Services,
+ pub local_config: LocalConfig,
+ pub discord_client: OauthClient,
+ pub http_client: reqwest::Client,
+}
+
+impl AppState {
+ pub async fn create(
+ services: Services,
+ configuration: &Configuration,
+ ) -> Result<AppHandle, AppError> {
+ let local_config: LocalConfig = serde_json::from_value(configuration.misc.clone())?;
+
+ let discord_client = discord_client(&local_config.oauth.discord)?;
+
+ Ok(AppHandle(Arc::new(Self {
+ services,
+ local_config,
+ discord_client,
+ http_client: reqwest::Client::new(),
+ })))
+ }
+}