Skip to content

Commit

Permalink
Add basic sessions and login
Browse files Browse the repository at this point in the history
  • Loading branch information
raffomania committed Dec 27, 2023
1 parent 2b77a00 commit 6496643
Show file tree
Hide file tree
Showing 16 changed files with 357 additions and 49 deletions.
165 changes: 153 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ clap = { version = "4.4.11", features = ["derive", "env"] }
include_dir = "0.7.3"
listenfd = "1.0.1"
mime_guess = "2.0.4"
serde = "1.0.193"
sqlx = { version = "0.7.3", features = ["runtime-tokio", "postgres", "tls-rustls", "migrate", "uuid", "time"] }
tokio = { version = "1.35.1", features = ["macros", "rt-multi-thread"] }
tower = "0.4.13"
tower-http = { version = "0.5.0", features = ["tracing", "trace"] }
tower-sessions = { version = "0.8.2", features = ["postgres-store", "deletion-task"] }
tracing = "0.1.40"
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
uuid = { version = "1.6.1", features = ["v4"] }

[build-dependencies]
railwind = "0.1.5"
walkdir = "2"

[dev-dependencies]
tower = { version = "0.4.13", features = ["util"] }
8 changes: 5 additions & 3 deletions src/app_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@ pub type Result<T> = std::result::Result<T, AppError>;
#[derive(Debug)]
pub enum AppError {
Anyhow(anyhow::Error),
NotFound(),
NotFound,
NotAuthenticated,
}

impl IntoResponse for AppError {
fn into_response(self) -> Response {
tracing::error!("{self:?}");
match self {
AppError::Anyhow(_) => (StatusCode::INTERNAL_SERVER_ERROR, "Internal Server Error"),
AppError::NotFound() => (StatusCode::NOT_FOUND, "Not Found"),
AppError::NotFound => (StatusCode::NOT_FOUND, "Not Found"),
AppError::NotAuthenticated => (StatusCode::UNAUTHORIZED, "Authentication failed"),
}
.into_response()
}
Expand All @@ -31,7 +33,7 @@ impl From<anyhow::Error> for AppError {
impl From<sqlx::Error> for AppError {
fn from(value: sqlx::Error) -> Self {
match value {
sqlx::Error::RowNotFound => Self::NotFound(),
sqlx::Error::RowNotFound => Self::NotFound,
other => Self::Anyhow(other.into()),
}
}
Expand Down
Loading

0 comments on commit 6496643

Please sign in to comment.