-
-
Notifications
You must be signed in to change notification settings - Fork 655
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Return body data when redirect in ServerFn #1513
Comments
I think this is a duplicate of #1358, so reading through the discussion there might be helpful. Unless it's different from this situation, this is determined by the way the browser handles the redirect, not by what the server function itself actually returns as an HTTP response. |
I see in the linked issue how they fix the problem, however, I see too much boilerplate for that matter... Response::builder()
.status(StatusCode::FOUND)
.header(header::LOCATION, "/login")
.body(axum::body::boxed(/* Encoded response */))
.unwrap() Is it good/bad idea? |
Just making sure we're on the same page: as I understand it, the HTTP response returned from a server function that redirects does already include the encoded body. You can see this if you use curl or a similar tool to make the request rather than doing it in the browser. It's just that the fetch request in the browser follows the redirect and does not give any access to that original body. |
Oh! Now I understand... I tried to tune a bit the fetch API but it looks like it's impossible to work along the fetch without using the trick showed in the issue you shared. |
Is your feature request related to a problem? Please describe.
When we have a server function in axum that redirects to a page, the Ok result is not returned in the redirect response.
https://github.com/leptos-rs/leptos/blob/main/examples/session_auth_axum/src/auth.rs#L174-L175
If instead of returning
Ok(())
, the return value is a String likeOk(String::from("done"))
the response will have a redirect status header but an empty body. So when handled the return value to handle errors, a success login will imply to handle the deserialization, as it will be empty:Describe the solution you'd like
Return the body data also along with the redirect
Describe alternatives you've considered
I handle as success the deserialization, although I don't think it's a good practice
Additional context
I have a shared LoginAction, so when I navigate away from the Login page and come back, the Deserialization error is there.
https://github.com/Bechma/realworld-leptos/blob/main/src/app.rs#L17
https://github.com/Bechma/realworld-leptos/blob/main/src/routes/login.rs#L15-L16
The text was updated successfully, but these errors were encountered: