Implement RBAC

This commit is contained in:
2024-10-04 10:31:09 +02:00
parent 5251a637de
commit 70afa170ec
5 changed files with 30 additions and 2 deletions

View File

@ -16,7 +16,7 @@ import { useAuth } from './auth'
const Routes = () => {
return (
<Router useAuth={useAuth}>
<PrivateSet unauthenticated="home">
<PrivateSet unauthenticated="home" roles="admin">
<Set wrap={ScaffoldLayout} title="Posts" titleTo="posts" buttonLabel="New Post" buttonTo="newPost">
<Route path="/admin/posts/new" page={PostNewPostPage} name="newPost" />
<Route path="/admin/posts/{id:Int}/edit" page={PostEditPostPage} name="editPost" />

View File

@ -2,7 +2,11 @@
import { Link } from '@redwoodjs/router'
import { Metadata } from '@redwoodjs/web'
import { useAuth } from 'src/auth'
const HomePage = () => {
const user = useAuth()
return (
<>
<Metadata title="Home" description="Home page" />
@ -15,6 +19,7 @@ const HomePage = () => {
My default route is named `home`, link to me with:
`<Link to={routes.home()}>Home</Link>`
*/}
{user && user.isAuthenticated + ' ' + user.hasRole('admin')}
<Link to={'/login'}>Login</Link>
</>
)