From a8cd8618a34017ca90a95283085b9764c09f53db Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Mon, 23 Aug 2021 12:01:04 +0200 Subject: [PATCH] Added lifetime thingy --- src/guards.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/guards.rs b/src/guards.rs index d475eb4..2994313 100644 --- a/src/guards.rs +++ b/src/guards.rs @@ -9,10 +9,10 @@ use rocket::{ use sha2::Sha256; /// Extracts a "Authorization: Bearer" string from the headers. -pub struct Bearer(String); +pub struct Bearer<'a>(&'a str); #[rocket::async_trait] -impl<'r> FromRequest<'r> for Bearer +impl<'r> FromRequest<'r> for Bearer<'r> { type Error = rb::errors::RBError; @@ -34,7 +34,7 @@ impl<'r> FromRequest<'r> for Bearer None => return Outcome::Forward(()), }; - Outcome::Success(Self(auth_string.to_string())) + Outcome::Success(Self(auth_string)) } } @@ -104,9 +104,10 @@ impl<'r> FromRequest<'r> for Admin async fn from_request(req: &'r Request<'_>) -> Outcome { - let user = try_outcome!(req.guard::().await); - if user.0.admin { - Outcome::Success(Self(user.0)) + let user = try_outcome!(req.guard::().await).0; + + if user.admin { + Outcome::Success(Self(user)) } else { Outcome::Forward(()) }