pub struct UseAuth { /* private fields */ }Expand description
Reactive auth hook result returned by use_auth.
Implementations§
Source§impl UseAuth
impl UseAuth
Sourcepub fn signal(&self) -> ReadSignal<AuthState>
pub fn signal(&self) -> ReadSignal<AuthState>
Return the underlying read-only Dioxus signal for advanced composition.
Sourcepub fn status(&self) -> AuthStatus
pub fn status(&self) -> AuthStatus
Return the explicit auth resolution status.
Sourcepub fn is_loading(&self) -> bool
pub fn is_loading(&self) -> bool
True while auth has not resolved to signed-in or signed-out yet.
Sourcepub fn is_signed_out(&self) -> bool
pub fn is_signed_out(&self) -> bool
True only when auth has resolved and no active session is known.
Sourcepub fn is_signed_in(&self) -> bool
pub fn is_signed_in(&self) -> bool
Whether a session is active.
Sourcepub fn require_signed_in(&self) -> Result<String, ClerkError>
pub fn require_signed_in(&self) -> Result<String, ClerkError>
Return the user id, or an error when auth is not signed in.
Returns ClerkError::NotLoaded while auth is still resolving and
ClerkError::Unauthenticated once it has resolved without a
signed-in user, so callers can wait out the former and redirect on the
latter without flashing sign-in UI at a signed-in user.
Sourcepub async fn get_token(&self) -> Result<Option<String>, ClerkError>
pub async fn get_token(&self) -> Result<Option<String>, ClerkError>
Get the active session token from clerk-js.
This mirrors Clerk React’s useAuth().getToken() convenience. The call
waits for the browser Clerk lifecycle to load before reading clerk-js.
Returns Err(ClerkError::Offline) when the browser is offline
(clerk-js 6 throws ClerkOfflineError here), a transient condition
callers can retry rather than treat as signed-out.
Sourcepub async fn get_token_with_options(
&self,
options: impl Into<Value>,
) -> Result<Option<String>, ClerkError>
pub async fn get_token_with_options( &self, options: impl Into<Value>, ) -> Result<Option<String>, ClerkError>
Get the active session token with Clerk getToken(...) options.
Sourcepub fn session_id(&self) -> Option<String>
pub fn session_id(&self) -> Option<String>
Active session id, if signed in and available.
Sourcepub fn org_permissions(&self) -> Vec<String>
pub fn org_permissions(&self) -> Vec<String>
Organization permissions from verified server auth.
Sourcepub fn has_role(&self, role: &str) -> bool
pub fn has_role(&self, role: &str) -> bool
True if the auth state includes the given server-verified org role.
Sourcepub fn has_permission(&self, permission: &str) -> bool
pub fn has_permission(&self, permission: &str) -> bool
True if the auth state includes the given server-verified org permission.
Sourcepub fn has(&self, requirement: &AuthRequirement) -> bool
pub fn has(&self, requirement: &AuthRequirement) -> bool
True if the auth state satisfies a rendering auth requirement.
Sourcepub fn sign_out(&self)
pub fn sign_out(&self)
Sign out after Clerk lifecycle loadedness.
This mirrors Clerk React’s useAuth().signOut() convenience. Failures
from the scheduled browser action are surfaced through
use_clerk_error. Use UseAuth::try_sign_out when the caller needs
to await completion or handle errors locally.
Sourcepub fn sign_out_with_options(&self, options: impl Into<Value>)
pub fn sign_out_with_options(&self, options: impl Into<Value>)
Sign out with Clerk signOut(...) options after Clerk lifecycle loadedness.
Sourcepub async fn try_sign_out(&self) -> Result<(), ClerkError>
pub async fn try_sign_out(&self) -> Result<(), ClerkError>
Sign out and return any lifecycle or clerk-js error.
Sourcepub async fn try_sign_out_with_options(
&self,
options: impl Into<Value>,
) -> Result<(), ClerkError>
pub async fn try_sign_out_with_options( &self, options: impl Into<Value>, ) -> Result<(), ClerkError>
Sign out with Clerk signOut(...) options and return any error.