aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrtkay123 <dev@kanjala.com>2026-04-12 12:54:36 +0200
committerrtkay123 <dev@kanjala.com>2026-04-12 12:54:36 +0200
commit34b2f8ff6a99471fbb72ed7c52a92b92645b0652 (patch)
tree214e46b91aa63234e7fa033de7001d70d06c1f46
parentb7c123490a1dad28c84960f00fe206fd8b43f0d4 (diff)
downloadsellershut-34b2f8ff6a99471fbb72ed7c52a92b92645b0652.tar.bz2
sellershut-34b2f8ff6a99471fbb72ed7c52a92b92645b0652.zip
fix: clippy
-rw-r--r--crates/api-auth/src/discord/mod.rs11
-rw-r--r--crates/api-auth/src/util.rs52
-rw-r--r--crates/sellershut/src/server/api/mod.rs2
-rw-r--r--crates/sellershut/src/server/api/routes/auth/authorised.rs2
-rw-r--r--crates/users/Cargo.toml10
-rw-r--r--crates/users/src/lib.rs14
6 files changed, 57 insertions, 34 deletions
diff --git a/crates/api-auth/src/discord/mod.rs b/crates/api-auth/src/discord/mod.rs
index 43a62bf..ffa5a68 100644
--- a/crates/api-auth/src/discord/mod.rs
+++ b/crates/api-auth/src/discord/mod.rs
@@ -1,15 +1,10 @@
use api_core::models::user::User;
-use async_session::{Session, serde_json};
use async_trait::async_trait;
-use oauth2::{AuthorizationCode, CsrfToken, TokenResponse};
-use redis::AsyncCommands;
use serde::{Deserialize, Serialize};
-use sh_util::cache::{CacheKey, RedisManager};
+use sh_util::cache::RedisManager;
use sqlx::PgPool;
-use crate::{
- BasicClient, CSRF_TOKEN, OauthDriver, SessionResponse, client::AuthHttpClient, error::AuthError,
-};
+use crate::{BasicClient, OauthDriver, SessionResponse, client::AuthHttpClient, error::AuthError};
// The user data we'll get back from Discord.
// https://discord.com/developers/docs/resources/user#user-object-user-structure
@@ -72,7 +67,7 @@ impl OauthDriver for AuthServiceDiscord {
crate::util::create_oauth_session(&self.client, &self.cache, &["identify", "email"]).await
}
- async fn save_session(&self, user: &User) -> Result<(), AuthError> {
+ async fn save_session(&self, _user: &User) -> Result<(), AuthError> {
todo!()
}
}
diff --git a/crates/api-auth/src/util.rs b/crates/api-auth/src/util.rs
index 0893bd5..b15a5e2 100644
--- a/crates/api-auth/src/util.rs
+++ b/crates/api-auth/src/util.rs
@@ -2,7 +2,7 @@ use api_core::models::user::User;
use async_session::{Session, serde_json};
use oauth2::{AuthorizationCode, CsrfToken, Scope, TokenResponse};
use redis::AsyncCommands;
-use serde::{Deserialize, de::DeserializeOwned};
+use serde::de::DeserializeOwned;
use sh_util::cache::{CacheKey, RedisManager};
use crate::{BasicClient, CSRF_TOKEN, SessionResponse, client::AuthHttpClient, error::AuthError};
@@ -44,7 +44,7 @@ pub async fn get_user<T>(
c: &BasicClient,
client: &AuthHttpClient,
code: &str,
- endpoint: &str,
+ _endpoint: &str,
) -> Result<User, AuthError>
where
User: TryFrom<T>,
@@ -71,33 +71,37 @@ where
User::try_from(user_data).map_err(|_e| AuthError::UserDeserialisation)
}
- pub async fn validate_session(cache: &RedisManager, cookie: &str, state: &str) -> Result<(), AuthError> {
- let id = Session::id_from_cookie_value(cookie)?;
- let cache_key = CacheKey::Session(&id);
- let mut cache = cache.get().await.unwrap();
- let session = cache.get::<_, String>(&cache_key).await?;
- let session: Session =
- serde_json::from_str(&session).map_err(|_e| AuthError::InvalidSession)?;
+pub async fn validate_session(
+ cache: &RedisManager,
+ cookie: &str,
+ state: &str,
+) -> Result<(), AuthError> {
+ let id = Session::id_from_cookie_value(cookie)?;
+ let cache_key = CacheKey::Session(&id);
+ let mut cache = cache.get().await.unwrap();
+ let session = cache.get::<_, String>(&cache_key).await?;
+ let session: Session =
+ serde_json::from_str(&session).map_err(|_e| AuthError::InvalidSession)?;
- match session.validate() {
- Some(session) => {
- // Extract the CSRF token from the session
- let stored_csrf_token = session.get::<CsrfToken>(CSRF_TOKEN);
+ match session.validate() {
+ Some(session) => {
+ // Extract the CSRF token from the session
+ let stored_csrf_token = session.get::<CsrfToken>(CSRF_TOKEN);
- if let Some(stored) = stored_csrf_token {
- // Cleanup the CSRF token session
- cache.del::<_, ()>(cache_key).await?;
+ if let Some(stored) = stored_csrf_token {
+ // Cleanup the CSRF token session
+ cache.del::<_, ()>(cache_key).await?;
- // Validate CSRF token is the same as the one in the auth request
- if *stored.secret() != state {
- Err(AuthError::TokenMismatch)
- } else {
- Ok(())
- }
+ // Validate CSRF token is the same as the one in the auth request
+ if *stored.secret() != state {
+ Err(AuthError::TokenMismatch)
} else {
- Err(AuthError::NoCSRFToken)
+ Ok(())
}
+ } else {
+ Err(AuthError::NoCSRFToken)
}
- None => Err(AuthError::MissingSession),
}
+ None => Err(AuthError::MissingSession),
}
+}
diff --git a/crates/sellershut/src/server/api/mod.rs b/crates/sellershut/src/server/api/mod.rs
index ebe29f8..4dd2635 100644
--- a/crates/sellershut/src/server/api/mod.rs
+++ b/crates/sellershut/src/server/api/mod.rs
@@ -21,7 +21,7 @@ pub mod routes;
)]
pub struct ApiDoc;
-pub async fn router(state: AppState, config: Config) -> Router<()> {
+pub async fn router(state: AppState, _config: Config) -> Router<()> {
let mut doc = ApiDoc::openapi();
doc.merge(ApiDocBase::openapi());
diff --git a/crates/sellershut/src/server/api/routes/auth/authorised.rs b/crates/sellershut/src/server/api/routes/auth/authorised.rs
index 94eaeca..a7e4c90 100644
--- a/crates/sellershut/src/server/api/routes/auth/authorised.rs
+++ b/crates/sellershut/src/server/api/routes/auth/authorised.rs
@@ -59,7 +59,7 @@ pub async fn authorised(
client.validate_session(&cookie, &params.state).await?;
- let user = client.get_user(&state.http_client, &params.code).await?;
+ let _user = client.get_user(&state.http_client, &params.code).await?;
Ok(String::default())
}
diff --git a/crates/users/Cargo.toml b/crates/users/Cargo.toml
new file mode 100644
index 0000000..e21ca6c
--- /dev/null
+++ b/crates/users/Cargo.toml
@@ -0,0 +1,10 @@
+[package]
+name = "users"
+version = "0.0.0"
+edition = "2024"
+license.workspace = true
+readme.workspace = true
+documentation.workspace = true
+homepage.workspace = true
+
+[dependencies]
diff --git a/crates/users/src/lib.rs b/crates/users/src/lib.rs
new file mode 100644
index 0000000..b93cf3f
--- /dev/null
+++ b/crates/users/src/lib.rs
@@ -0,0 +1,14 @@
+pub fn add(left: u64, right: u64) -> u64 {
+ left + right
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn it_works() {
+ let result = add(2, 2);
+ assert_eq!(result, 4);
+ }
+}