Skip to main content

create_session

Function create_session 

Source
pub async fn create_session(
    server_info: &BuiServerAddrInfo,
    jar: Arc<RwLock<CookieStore>>,
) -> Result<HttpSession, Error>
Expand description

Creates an authenticated HttpSession by making an initial request with the provided token.

This function establishes a session with the server by making an initial authenticated request, which typically results in the server setting session cookies that will be used for subsequent requests.

§Arguments

  • server_info - Server address and authentication information
  • jar - Thread-safe cookie store for managing session cookies

§Returns

An authenticated HttpSession ready for making requests, or an error if the initial authentication request fails.

§Examples

use strand_bui_backend_session::create_session;
use strand_bui_backend_session_types::AccessToken;
use std::sync::{Arc, RwLock};

let jar = Arc::new(RwLock::new(cookie_store::CookieStore::new(None)));
let server_info = strand_bui_backend_session_types::BuiServerAddrInfo::new(
    "127.0.0.1:8080".parse()?,
    AccessToken::PreSharedToken("secret123".to_string())
);

let session = create_session(&server_info, jar).await?;