Compare commits

..

4 Commits

Author SHA1 Message Date
spinline
518af10cd7 fix: use .0 for reading and .1 for writing signals
All checks were successful
Build MIPS Binary / build (push) Successful in 5m20s
2026-02-09 22:37:06 +03:00
spinline
0304c5cb7d fix: prevent panic by using signals for redirects and fix auth flow
Some checks failed
Build MIPS Binary / build (push) Failing after 1m15s
2026-02-09 22:32:19 +03:00
spinline
cee609700a fix: use navigate inside Router context and fix auth redirect flow
Some checks failed
Build MIPS Binary / build (push) Has been cancelled
2026-02-09 22:30:59 +03:00
spinline
a9de8aeb5a debug: add more SSE logging to trace message receiving
All checks were successful
Build MIPS Binary / build (push) Successful in 5m20s
2026-02-09 22:21:39 +03:00
2 changed files with 46 additions and 22 deletions

View File

@@ -25,9 +25,7 @@ pub fn App() -> impl IntoView {
match setup_res {
Ok(status) => {
if !status.completed {
log::info!("Setup not completed, redirecting to /setup");
let navigate = use_navigate();
navigate("/setup", Default::default());
log::info!("Setup not completed");
is_loading.1.set(false);
return;
}
@@ -48,27 +46,12 @@ pub fn App() -> impl IntoView {
}
is_authenticated.1.set(true);
let pathname = window().location().pathname().unwrap_or_default();
if pathname == "/login" || pathname == "/setup" {
log::info!("Already authenticated, redirecting to home");
let navigate = use_navigate();
navigate("/", Default::default());
}
}
Ok(false) => {
log::info!("Not authenticated");
let pathname = window().location().pathname().unwrap_or_default();
if pathname != "/login" && pathname != "/setup" {
let navigate = use_navigate();
navigate("/login", Default::default());
}
}
Err(e) => {
log::error!("Auth check failed: {:?}", e);
let navigate = use_navigate();
navigate("/login", Default::default());
}
}
@@ -92,10 +75,39 @@ pub fn App() -> impl IntoView {
<div class="relative w-full h-screen" style="height: 100dvh;">
<Router>
<Routes fallback=|| view! { <div class="p-4">"404 Not Found"</div> }>
<Route path=leptos_router::path!("/login") view=move || view! { <Login /> } />
<Route path=leptos_router::path!("/setup") view=move || view! { <Setup /> } />
<Route path=leptos_router::path!("/login") view=move || {
let authenticated = is_authenticated.0.get();
Effect::new(move |_| {
if authenticated {
log::info!("Already authenticated, redirecting to home");
let navigate = use_navigate();
navigate("/", Default::default());
}
});
view! { <Login /> }
} />
<Route path=leptos_router::path!("/setup") view=move || {
Effect::new(move |_| {
if is_authenticated.0.get() {
let navigate = use_navigate();
navigate("/", Default::default());
}
});
view! { <Setup /> }
} />
<Route path=leptos_router::path!("/") view=move || {
Effect::new(move |_| {
if !is_loading.0.get() && !is_authenticated.0.get() {
log::info!("Not authenticated, redirecting to login");
let navigate = use_navigate();
navigate("/login", Default::default());
}
});
view! {
<Show when=move || !is_loading.0.get() fallback=|| view! {
<div class="flex items-center justify-center h-screen bg-base-100">
@@ -112,6 +124,13 @@ pub fn App() -> impl IntoView {
}/>
<Route path=leptos_router::path!("/settings") view=move || {
Effect::new(move |_| {
if !is_authenticated.0.get() {
let navigate = use_navigate();
navigate("/login", Default::default());
}
});
view! {
<Show when=move || !is_loading.0.get() fallback=|| ()>
<Show when=move || is_authenticated.0.get() fallback=|| ()>
@@ -128,4 +147,4 @@ pub fn App() -> impl IntoView {
<ToastContainer />
</div>
}
}
}

View File

@@ -133,12 +133,16 @@ pub fn provide_torrent_store() {
let mut disconnect_notified = false;
loop {
log::debug!("SSE: Creating EventSource...");
let es_result = EventSource::new("/api/events");
match es_result {
Ok(mut es) => {
log::debug!("SSE: EventSource created, subscribing to message channel...");
if let Ok(mut stream) = es.subscribe("message") {
log::debug!("SSE: Subscribed to message channel");
let mut got_first_message = false;
while let Some(Ok((_, msg))) = stream.next().await {
log::debug!("SSE: Received message: {:?}", msg.data());
if !got_first_message {
got_first_message = true;
backoff_ms = 1000;
@@ -150,10 +154,11 @@ pub fn provide_torrent_store() {
}
if let Some(data_str) = msg.data().as_string() {
log::debug!("SSE: Parsing JSON: {}", data_str);
if let Ok(event) = serde_json::from_str::<AppEvent>(&data_str) {
match event {
AppEvent::FullList { torrents: list, .. } => {
log::debug!("SSE: Received FullList with {} torrents", list.len());
log::info!("SSE: Received FullList with {} torrents", list.len());
torrents.update(|map| {
let new_hashes: std::collections::HashSet<String> = list.iter().map(|t| t.hash.clone()).collect();
map.retain(|hash, _| new_hashes.contains(hash));