Skip to main content

Crate dioxus_cookie

Crate dioxus_cookie 

Source
Expand description

Cross-platform cookie management for Dioxus fullstack applications.

Dioxus apps can target web, desktop, iOS, and Android from a single codebase. Native platforms lack built-in cookie storage—when a server function sets a cookie, native apps silently discard it. dioxus-cookie provides a unified cookie API that works across all supported platforms.

§Quick Start

fn main() {
    dioxus_cookie::init();  // Call before dioxus::launch()
    dioxus::launch(App);
}

#[server]
async fn login(credentials: Credentials) -> Result<(), ServerFnError> {
    dioxus_cookie::set("session", &token, &CookieOptions::default())?;
    Ok(())
}

§Platform Behavior

PlatformStorage
ServerHTTP Set-Cookie headers
Browserdocument.cookie
DesktopSystem keyring
iOSKeychain
AndroidKeyStore (default) or encrypted file (android-file feature)

§Features

  • server — Server-side cookie handling via HTTP headers
  • desktop — Desktop platforms with system keyring storage
  • mobile — iOS/Android with Keychain/KeyStore storage
  • android-file — Force encrypted file storage on Android (skip KeyStore)
  • mobile-sim — Mobile + file fallback for simulator/emulator development
  • file-store — Encrypted file fallback (see security note below)

§File Storage Fallback

The file-store feature provides encrypted file-based storage for environments where the system keychain is unavailable (iOS Simulator, Android Emulator, Linux without D-Bus, CI/CD pipelines, Docker containers).

Security limitations:

  • Debug builds only — automatically disabled in release builds
  • Obfuscation, not protection — deters casual inspection but does not protect against local attackers with file system access
  • Not for production — production apps must use real keychain storage

Structs§

CookieError
Error type for cookie operations.
CookieOptions
Configuration options for setting cookies.

Enums§

SameSite
Cross-site request cookie policy (SameSite attribute).

Functions§

clear
Deletes a cookie by name.
get
Retrieves a cookie value by name.
get_internal
Retrieves a cookie value, bypassing the HttpOnly restriction.
get_storage_type
Returns the active storage backend type.
init
Initialize the cookie system.
list_names
Lists names of all accessible cookies.
set
Sets a cookie with the given name, value, and options.