semi working backend (it works but not really usable)

This commit is contained in:
2025-07-13 00:38:17 +02:00
parent 5711f84172
commit c2c7454cd4
5 changed files with 61 additions and 12 deletions
+42
View File
@@ -0,0 +1,42 @@
use dioxus::prelude::use_navigator;
use wasm_bindgen::JsCast;
use web_sys::{window, HtmlDocument};
pub fn set_cookie(name: &str, value: &str) {
let Some(document) = window().and_then(|w| w.document()) else {
return;
};
let Ok(html_doc) = document.dyn_into::<HtmlDocument>() else {
return;
};
let cookie = format!("{name}={value}; path=/");
let _ = html_doc.set_cookie(&cookie);
}
pub fn get_cookie(name: &str) -> Option<String> {
let Some(document) = window().and_then(|w| w.document()) else {
return None;
};
let Ok(html_doc) = document.dyn_into::<HtmlDocument>() else {
return None;
};
let Ok(cookie_string) = html_doc.cookie() else {
return None;
};
for cookie in cookie_string.split(';') {
let cookie = cookie.trim();
if let Some((k, v)) = cookie.split_once('=') {
if k == name {
return Some(v.to_string());
}
}
}
None
}
pub fn redirect(target: &str) {
use_navigator().push(target);
}