Skip to content

Commit

Permalink
feat: Use ViewConfig to protect views
Browse files Browse the repository at this point in the history
  • Loading branch information
mshabarov committed Mar 28, 2024
1 parent d5a47e9 commit 918370f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/main/frontend/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ let routing = protectRoutes([
element: <Layout />,
handle: { title: 'Main' },
children: [
{ path: '/', element: <Public />, handle: { title: 'Public', requiresLogin: false } },
{ path: '/about', element: <About />, handle: { title: 'Welcome', requiresLogin: true } },
{ path: '/hilla', element: <Hilla />, handle: { title: 'Hilla', rolesAllowed: ['ROLE_USER'] } }
{ 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' } }
Expand Down
5 changes: 5 additions & 0 deletions src/main/frontend/views/about.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { VerticalLayout } from "@vaadin/react-components/VerticalLayout.js";
import type {ViewConfig} from "@vaadin/hilla-file-router/types.js";

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

/**
* Hilla views that allows access only for authenticated users.
Expand Down
7 changes: 7 additions & 0 deletions src/main/frontend/views/hilla.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ import { HelloEndpoint } from "Frontend/generated/endpoints";
import { useState } from "react";
import {VerticalLayout} from "@vaadin/react-components/VerticalLayout.js";

import type {ViewConfig} from "@vaadin/hilla-file-router/types.js";

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

/**
* Hilla view that allows access only for users with a role 'USER'
*/
Expand Down

0 comments on commit 918370f

Please sign in to comment.