Skip to main content

AuthState

Struct AuthState 

Source
#[non_exhaustive]
pub struct AuthState { /* private fields */ }
Expand description

App-visible authentication state for components and hooks.

status is the single source of truth for the signed-in answer; signed-in checks derive from it so contradictory states cannot be represented. The fields are private so status and user_id cannot be mutated out of step with each other; read them through the accessors (status, user_id, …) and build values through the constructors and with_* setters. SSR initial state carries crate::ssr::InitialAuthSnapshot instead. Browser loadedness is client lifecycle state, so server-rendered auth snapshots do not set is_loaded.

Implementations§

Source§

impl AuthState

Source

pub fn loading() -> Self

Auth state before Clerk has supplied a reliable answer.

Source

pub fn signed_out() -> Self

Auth state representing a resolved signed-out session.

is_loaded stays false: browser loadedness is client lifecycle state, not part of the auth answer. Set it explicitly when modeling a client where clerk-js has finished loading.

Source

pub fn signed_in(user_id: impl Into<String>) -> Self

Auth state representing a signed-in session for the given user id. Chain the with_* setters to add optional session/org fields (and is_loaded).

An empty user id cannot represent a signed-in session and produces AuthState::signed_out, matching From<&ClerkAuth>.

Source

pub fn with_loaded(self, is_loaded: bool) -> Self

Set whether clerk-js has finished loading on the client.

Source

pub fn with_session_id(self, session_id: impl Into<String>) -> Self

Set the active session id.

Source

pub fn with_org_id(self, org_id: impl Into<String>) -> Self

Set the active organization id.

Source

pub fn with_org_slug(self, org_slug: impl Into<String>) -> Self

Set the active organization slug.

Source

pub fn with_org_role(self, org_role: impl Into<String>) -> Self

Set the organization role from verified server auth.

Source

pub fn with_org_permissions( self, org_permissions: impl IntoIterator<Item = impl Into<String>>, ) -> Self

Set the organization permissions from verified server auth.

Source

pub fn status(&self) -> AuthStatus

Explicit auth resolution status: the single source of truth for the signed-in answer.

Source

pub fn is_loaded(&self) -> bool

Whether clerk-js has finished loading on the client.

Source

pub fn user_id(&self) -> Option<&str>

Clerk user id, if signed in.

Source

pub fn session_id(&self) -> Option<&str>

Active session id, if any.

Source

pub fn org_id(&self) -> Option<&str>

Org id from verified server auth, if any.

Source

pub fn org_slug(&self) -> Option<&str>

Org slug from verified server auth, if any.

Source

pub fn org_role(&self) -> Option<&str>

Org role from verified server auth, if any.

Source

pub fn org_permissions(&self) -> &[String]

Org permissions from verified server auth.

Source

pub fn is_signed_in(&self) -> bool

True when a signed-in session is known.

Source

pub fn is_loading(&self) -> bool

True while auth has not resolved to signed-in or signed-out yet.

Source

pub fn is_signed_out(&self) -> bool

True only when auth has resolved and no active session is known; false while auth is still loading.

Source

pub fn require_signed_in(&self) -> Result<&str, ClerkError>

Return the user id for signed-in auth state.

Preserves the loading/signed-out distinction the rest of the API keeps: ClerkError::NotLoaded while auth has not resolved yet (retry or wait), ClerkError::Unauthenticated only once auth has resolved without a signed-in user (redirect to sign-in).

Source

pub fn has_role(&self, role: &str) -> bool

True if the auth state includes the given server-verified org role.

Source

pub fn has_permission(&self, permission: &str) -> bool

True if the auth state includes the given server-verified org permission.

Source

pub fn has(&self, requirement: &AuthRequirement) -> bool

True if the auth state satisfies a rendering auth requirement.

Role and permission requirements imply a signed-in session; they are never satisfied by a loading or signed-out state.

Trait Implementations§

Source§

impl Clone for AuthState

Source§

fn clone(&self) -> AuthState

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for AuthState

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for AuthState

Source§

impl From<&ClerkAuth> for AuthState

Converts server-verified claims into app-visible auth state, cloning the claim fields. See From<ClerkAuth>.

Source§

fn from(c: &ClerkAuth) -> Self

Converts to this type from the input type.
Source§

impl From<ClerkAuth> for AuthState

Converts server-verified claims into app-visible auth state.

is_loaded stays false: these claims come from the server, where clerk-js does not exist, so browser loadedness cannot be inferred.

Source§

fn from(c: ClerkAuth) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for AuthState

Source§

fn eq(&self, other: &AuthState) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for AuthState

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DependencyElement for T
where T: 'static + PartialEq + Clone,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> InitializeFromFunction<T> for T

Source§

fn initialize_from_function(f: fn() -> T) -> T

Create an instance of this type from an initialization function
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<Ret> SpawnIfAsync<(), Ret> for Ret

Source§

fn spawn(self) -> Ret

Spawn the value into the dioxus runtime if it is an async block
Source§

impl<T, O> SuperFrom<T> for O
where O: From<T>,

Source§

fn super_from(input: T) -> O

Convert from a type to another type.
Source§

impl<T, O, M> SuperInto<O, M> for T
where O: SuperFrom<T, M>,

Source§

fn super_into(self) -> O

Convert from a type to another type.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more