frontend: Add redirect to login page for unauthorized requests

This commit is contained in:
Lennart
2024-11-03 16:23:37 +01:00
parent aead176cdb
commit 31c7143dd8
2 changed files with 35 additions and 7 deletions

View File

@@ -1,8 +1,9 @@
use actix_web::{
body::BoxBody,
http::{header, StatusCode},
FromRequest, HttpMessage, HttpResponse, ResponseError,
};
use derive_more::Display;
use derive_more::{derive::Deref, Display};
use serde::{Deserialize, Serialize};
use std::future::{ready, Ready};
@@ -20,7 +21,7 @@ impl ResponseError for UnauthorizedError {
fn status_code(&self) -> actix_web::http::StatusCode {
StatusCode::UNAUTHORIZED
}
fn error_response(&self) -> actix_web::HttpResponse<actix_web::body::BoxBody> {
fn error_response(&self) -> HttpResponse<BoxBody> {
HttpResponse::build(StatusCode::UNAUTHORIZED)
.insert_header((
header::WWW_AUTHENTICATE,
@@ -35,7 +36,6 @@ impl ResponseError for UnauthorizedError {
}
impl FromRequest for User {
// type Error = actix_web::Error;
type Error = UnauthorizedError;
type Future = Ready<Result<Self, Self::Error>>;
@@ -47,7 +47,6 @@ impl FromRequest for User {
req.extensions()
.get::<Self>()
.cloned()
// .ok_or(ErrorUnauthorized("Not authenticated")),
.ok_or(UnauthorizedError),
)
}