Skip to main content

Module auth_context

Module auth_context 

Source
Expand description

Reactive authentication context for Orbital applications.

This module gives Orbital apps one shared place to store the current AuthSession and a lightweight refresh token used to refetch it from the server. Most apps provide it once near the router root and then access it with use_auth_context, use_auth_state, or use_authenticated_user.

§Typical setup

use leptos::prelude::*;
use orbital::{init_auth_resource, provide_auth_context, AuthSession};

#[component]
fn AppRoot() -> impl IntoView {
    let auth = provide_auth_context(AuthSession::default());
    let _session_resource = init_auth_resource(auth.clone());

    view! { <main>"App shell"</main> }
}

After a sign-in, sign-out, or account change, call AuthContext::trigger_refresh to ask the client-side session resource to load the latest backend session state.

Structs§

AuthContext
Shared authentication context containing session state and refresh controls.

Functions§

provide_auth_context
Provide AuthContext to the component tree and return it.
use_auth_context
Access the shared AuthContext.
use_auth_state
Reactive memo for the current AuthSession.
use_authenticated_user
Reactive memo for the authenticated user profile, if present.