From 44e61805b0d8a14d41b931662d497204f51ec5c5 Mon Sep 17 00:00:00 2001 From: Sphereso Date: Tue, 9 Jul 2024 10:00:31 +0200 Subject: [PATCH] backend: fix imports --- crates/backend/src/auth.rs | 31 +++---------------------------- crates/backend/src/main.rs | 1 - 2 files changed, 3 insertions(+), 29 deletions(-) diff --git a/crates/backend/src/auth.rs b/crates/backend/src/auth.rs index 60e37d5..bfea0c4 100644 --- a/crates/backend/src/auth.rs +++ b/crates/backend/src/auth.rs @@ -1,14 +1,8 @@ -use core::fmt; use std::{pin::Pin, time::SystemTime}; -use actix_web::{ - error::ErrorUnauthorized, - http::{header, StatusCode}, - web, Error, FromRequest, HttpRequest, HttpResponse, ResponseError, -}; +use actix_web::{error::ErrorUnauthorized, http::header, web, Error, FromRequest, HttpRequest}; use futures::Future; -use jsonwebtoken::{DecodingKey, EncodingKey, Header, Validation}; -use migration::token; +use jsonwebtoken::{DecodingKey, EncodingKey, Header}; use sea_orm::EntityTrait; use serde::{Deserialize, Serialize}; use uuid::Uuid; @@ -46,7 +40,7 @@ impl AuthedUser { let header = req .headers() .get(header::AUTHORIZATION) - .ok_or(AuthorizationError)?; + .ok_or(ErrorUnauthorized("Unauthorized"))?; if header.len() < 8 { return Err(ErrorUnauthorized("Unauthorized")); @@ -102,22 +96,3 @@ impl FromRequest for AuthedUser { }) } } - -#[derive(Debug)] -struct AuthorizationError; - -impl fmt::Display for AuthorizationError { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - fmt::Display::fmt(&self.status_code(), f) - } -} - -impl ResponseError for AuthorizationError { - fn status_code(&self) -> actix_web::http::StatusCode { - StatusCode::UNAUTHORIZED - } - - fn error_response(&self) -> actix_web::HttpResponse { - HttpResponse::build(self.status_code()).finish() - } -} diff --git a/crates/backend/src/main.rs b/crates/backend/src/main.rs index 89213cf..217e0c4 100644 --- a/crates/backend/src/main.rs +++ b/crates/backend/src/main.rs @@ -1,5 +1,4 @@ use actix_web::{web, App, HttpServer}; -use jsonwebtoken::EncodingKey; use migration::MigratorTrait; use sea_orm::{Database, DatabaseConnection}; use std::env;