feat: add authentication #6
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "feat/add-authentication"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Adds bearer auth for the POST /pump (write) endpoint
@ -52,0 +67,4 @@.ok_or(StatusCode::UNAUTHORIZED)?;let is_authorized =bcrypt::verify(header_text, &login_hash).map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;This might just be my unfamiliarity with Rust, but shouldn't unhandled errors be caught by your top-level route handler? Like errors bubbling up is actually desired because it means you don't need to manually throw/respond with an internal server error in a bunch of different places.
Kinda a noob but this is my understanding.
In Rust, errors are just values like Result<T, E> and as such means that they don't propagate up on their own and need to be handled explicitly. The ? operator makes the error propagate, but it still needs to be mapped to the type the function expects.
Thinking about what you said though, I think it might be possible to make an implementation of IntoResponse with From that could default to 500 though (when using ? operator) which would be nice. I will look into that and see if I can make it separately. I saw it done similarly here at point 5 which looks applicable.