Skip to content
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

Hilla doesn't redirect to a given URL when logout with Hilla's useAuth API #2235

Closed
Tracked by #5012
mshabarov opened this issue Mar 19, 2024 · 8 comments · Fixed by #2432
Closed
Tracked by #5012

Hilla doesn't redirect to a given URL when logout with Hilla's useAuth API #2235

mshabarov opened this issue Mar 19, 2024 · 8 comments · Fixed by #2432
Assignees
Labels
bug Something isn't working hilla Issues related to Hilla Impact: High Severity: Major

Comments

@mshabarov
Copy link
Contributor

mshabarov commented Mar 19, 2024

Description of the bug

Hilla doesn't redirect to a logoutSuccessfulUrl being set with VaadinWebSecurity::setLoginView(http, "/login", "/") if the logout method uses Hilla's provided useAuth::logout API.

It performs the logout successfully, but the page isn't redirected and the page content is visible.

If I logout from a Hilla view, it redirects me to login page, which also a bit unexpected, but better than keeping the content of the current page.

Here is how I configure my logout:

MainLayout.tsx:

import {useAuth} from "../auth";
...
const { state, logout } = useAuth();
...
<Button onClick={async () => logout()}>Sign out</Button>

auth.tsx

import { UserInfoService } from 'Frontend/generated/endpoints';
import {configureAuth} from "@vaadin/hilla-react-auth";

const auth = configureAuth(UserInfoService.getUserInfo, {
    getRoles: (userInfo) => userInfo.authorities,
});

export const useAuth = auth.useAuth;
export const AuthProvider = auth.AuthProvider;

Browser sends POST "/logout" request to server and it's caught by UidlRedirectStrategy. Then it falls into super.sendRedirect(request, response, url); and redirect doesn't happen for some reason.

Expected behavior

Flow should redirect to "/" after logout.

Minimal reproducible example

  1. Checkout branch https://github.com/vaadin/flow-hilla-hybrid-example/tree/stateful-auth
  2. mvn
  3. Log in with admin/admin
  4. Navigate to Flow view
  5. Click on Logout button
  6. Browser the Flow content is still there.

Versions

  • Vaadin / Flow version: 24.4.0.alpha15
@mshabarov
Copy link
Contributor Author

This needs a change in hilla-react-auth, so that it redirects to a root "/" by default.
Transferring this issue to Hilla.

@mshabarov mshabarov transferred this issue from vaadin/flow Mar 20, 2024
@mshabarov mshabarov changed the title Flow doesn't redirect to a given URL when logout with Hilla's useAuth API Hilla doesn't redirect to a given URL when logout with Hilla's useAuth API Mar 20, 2024
@TatuLund
Copy link
Contributor

Currently I am doing that like this TatuLund/hilla-v2-demo@ccc5570

@platosha
Copy link
Contributor

#2237 was causing this, now it's fixed.

@platosha platosha reopened this Mar 21, 2024
@platosha
Copy link
Contributor

platosha commented Mar 21, 2024

Ah sorry, logout redirect... 😅 #2237 isn't related then.

@platosha platosha added the hilla Issues related to Hilla label May 13, 2024
@Lodin Lodin self-assigned this May 14, 2024
@Lodin
Copy link
Contributor

Lodin commented May 14, 2024

@mshabarov, it looks like there is no stateful-auth branch anymore 🤔

@platosha
Copy link
Contributor

@Lodin it was merged into 24.4, I think.

@Lodin
Copy link
Contributor

Lodin commented May 15, 2024

@mshabarov, @platosha, @Legioth, what would you expect on logout?

  • The page fully reloads
  • The page is updated using the React Router capabilities

@Legioth
Copy link
Member

Legioth commented May 15, 2024

It's always a good practice to reload the page whenever the authentication state changes. When logging out, one of the main benefits is that you can ensure that no sensitive data remains referenced in JS variables.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working hilla Issues related to Hilla Impact: High Severity: Major
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants