Skip to content

Commit

Permalink
Actually fix redirecting to login page since yew_router::Redirect doe…
Browse files Browse the repository at this point in the history
…sn't do a real redirect
  • Loading branch information
itsjunetime committed Oct 22, 2024
1 parent e8ea13f commit 562428d
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions frontend/src/post_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,20 @@ pub fn post_list<P: PostViewProvider>(props: &PostListProps<P>) -> Html {

let posts_html = match &*post_list {
None => html! { <p>{ "Loading posts..." }</p> },
Some(Err(GetPostListErr::Unauthorized)) => return html! {
Some(Err(GetPostListErr::Unauthorized)) => {
// we're assuming that if they get 'unauthorized', then they probably are trying to
// access the admin page.
<Redirect<AnyRoute> to={ AnyRoute::new("/login?redir_to=/admin") }/>
let res = web_sys::window()
.expect("There's gotta be a window")
.location()
.replace("/login?redir_to=admin");
return match res {
Ok(()) => html!{},
Err(_) => html!{ <>
<p>{ "We couldn't redirect you to the login page. " }</p>
<a href="/login?redir_to=admin">{ "Please click this link." }</a>
</> }
}
},
Some(Err(GetPostListErr::Other(err))) => html! {
<><h1>{ "Couldn't get posts" }</h1><p>{ err }</p></>
Expand Down

0 comments on commit 562428d

Please sign in to comment.