Skip to main content

set_cookie

Function set_cookie 

Source
pub fn set_cookie(name: &str, value: &str, max_age_secs: u64)
Expand description

Queue an HttpOnly auth cookie on the outgoing response.

The cookie is configured with:

  • HttpOnly — not accessible via JavaScript (prevents XSS token theft)
  • Secure — only sent over HTTPS
  • SameSite=Strict — not sent on cross-origin requests (prevents CSRF)
  • Path=/ — available on all routes

For custom cookie options, use set_cookie_with instead.

§Example

use dioxus_cloudflare::cf;

#[server]
pub async fn login(token: String) -> Result<(), ServerFnError> {
    cf::set_cookie("session", &token, 60 * 60 * 24 * 7);
    Ok(())
}