pub struct AdminAuth { /* private fields */ }server only.Expand description
Authentication and authorization checker for admin panel.
This struct extracts authentication state from the HTTP request and provides methods to check authentication and permissions.
Implementations§
Source§impl AdminAuth
impl AdminAuth
Sourcepub fn from_request(request: &ServerFnRequest) -> Self
pub fn from_request(request: &ServerFnRequest) -> Self
Sourcepub fn from_arc_request(request: &Arc<Request>) -> Self
pub fn from_arc_request(request: &Arc<Request>) -> Self
Sourcepub fn auth_state(&self) -> Option<&AuthState>
pub fn auth_state(&self) -> Option<&AuthState>
Returns the AuthState if available.
Sourcepub fn is_authenticated(&self) -> bool
pub fn is_authenticated(&self) -> bool
Sourcepub fn is_staff(&self) -> bool
pub fn is_staff(&self) -> bool
Checks if the user is a staff member (admin access).
§Returns
true if the user is staff/admin, false otherwise
Sourcepub fn require_authenticated(&self) -> Result<(), ServerFnError>
pub fn require_authenticated(&self) -> Result<(), ServerFnError>
Requires authentication, returning an error if not authenticated.
§Errors
Returns ServerFnError with status 401 if not authenticated
Sourcepub fn require_staff(&self) -> Result<(), ServerFnError>
pub fn require_staff(&self) -> Result<(), ServerFnError>
Requires staff (admin) status, returning an error if not staff.
§Errors
Returns ServerFnError with status 403 if not staff
Sourcepub async fn require_model_permission(
&self,
model_admin: &dyn ModelAdmin,
user: &dyn AdminUser,
permission: ModelPermission,
) -> Result<(), ServerFnError>
pub async fn require_model_permission( &self, model_admin: &dyn ModelAdmin, user: &dyn AdminUser, permission: ModelPermission, ) -> Result<(), ServerFnError>
Checks model-level permission using ModelAdmin, returning an error if denied.
This method first verifies staff status, then delegates to the
ModelAdmin’s permission method for the specified permission type.
The caller is responsible for providing the authenticated user object
extracted from the DI context via AdminAuthenticatedUser. The user
is passed as a &dyn AdminUser trait object, which is produced by the
type-erased user loader registered during admin route setup.
§Arguments
model_admin- The model admin to check permissions againstuser- The authenticated user object as a trait objectpermission- The type of permission to check
§Errors
Returns ServerFnError with status 401 if not authenticated,
403 if not staff or if model-level permission is denied
Auto Trait Implementations§
impl Freeze for AdminAuth
impl RefUnwindSafe for AdminAuth
impl Send for AdminAuth
impl Sync for AdminAuth
impl Unpin for AdminAuth
impl UnsafeUnpin for AdminAuth
impl UnwindSafe for AdminAuth
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more