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

ViewConfig has no effect for authentication properties #2276

Closed
mshabarov opened this issue Mar 28, 2024 · 3 comments
Closed

ViewConfig has no effect for authentication properties #2276

mshabarov opened this issue Mar 28, 2024 · 3 comments
Labels
bug Something isn't working hilla Issues related to Hilla

Comments

@mshabarov
Copy link
Contributor

Describe the bug

Suppose I want to protect my Hilla views with loginRequired and rolesAllowed using ViewConfig API:

export const config: ViewConfig = {
    loginRequired: true
};

and

export const config: ViewConfig = {
    loginRequired: true,
    rolesAllowed: ['ROLE_USER'],
};

and setting the following routes in routes.tsx:

let routing = protectRoutes([
    {
        element: <Layout />,
        handle: { title: 'Main' },
        children: [
            { path: '/', element: <Public />, handle: { title: 'Public' } },
            { path: '/about', element: <About />, handle: { title: 'Welcome' } },
            { path: '/hilla', element: <Hilla />, handle: { title: 'Hilla' } }
        ],
    },
    { path: '/login', element: <Login />, handle: { title: 'Login' } }
]) as RouteObject[];

This has no effect unfortunately: if I log in under another user with another role, the view is accessible, and if I change to loginRequired: false, Hilla redirects me to /login.

If I remove ViewConfig from Hilla views, the behaviour is the same: the application just requires me to login.

Expected-behavior

Hilla should take role into account and not require me to log in if I set loginRequired: false.

Reproduction

Can be reproduced with the branch vaadin/flow-hilla-hybrid-example#30.

System Info

Vaadin 24.4.0.alpha17.

@mshabarov mshabarov added bug Something isn't working hilla Issues related to Hilla labels Mar 28, 2024
@Legioth
Copy link
Member

Legioth commented Mar 28, 2024

export const config is a feature of the FS router. If you don't use it but instead configure routes manually, then you should put access control in handle in the route configuration rather than in export const config

@mshabarov
Copy link
Contributor Author

I noticed it when I tested #2250, where FS router is used.
But yeah, good to know that it's not applicable for manual routes.

@platosha platosha closed this as completed Apr 2, 2024
@platosha
Copy link
Contributor

platosha commented Apr 2, 2024

Closing as won't fix. ViewConfig by design does not apply to manually declared routes.

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
Projects
None yet
Development

No branches or pull requests

3 participants