Skip to content

Commit

Permalink
Merge pull request #115 from LerianStudio/feature/not-authorized-page
Browse files Browse the repository at this point in the history
✨ feat: Added not authorized page
  • Loading branch information
caioaletroca authored Jan 16, 2025
2 parents 987f31c + d55b3d2 commit 44cf689
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
2 changes: 2 additions & 0 deletions locales/extracted/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,8 @@
"ledgers.toast.update.success": "Ledger changes saved successfully",
"ledgersPage.alert.description": "To use ledger features, you need to create an organization.",
"ledgersPage.alert.title": "Organization Required",
"notAuthorized.backToHome": "Back to Home",
"notAuthorized.title": "You are not authorized to access this page.",
"notFound.backToHome": "Back to Home",
"notFound.description": "Try accessing another page.",
"notFound.title": "The page you are looking for does not exist.",
Expand Down
6 changes: 4 additions & 2 deletions locales/extracted/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -328,5 +328,7 @@
"settings.system.language": "Idioma",
"settings.system.locale.description": "Selecione o idioma que você gostaria de usar no Midaz.",
"settings.system.paper.description": "Ajustes as preferências de sistema.",
"settings.tabs.system": "Sistema"
}
"settings.tabs.system": "Sistema",
"notAuthorized.backToHome": "Voltar para Home",
"notAuthorized.title": "Você não tem autorização para acessar esta página."
}
28 changes: 26 additions & 2 deletions src/context/permission-provider/route-enforcer.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { redirect } from 'next/navigation'
import Link from 'next/link'
import { usePermissions } from './permission-provider-client'
import { useIntl } from 'react-intl'
import { Button } from '@/components/ui/button'

type RouteEnforcerProps = React.PropsWithChildren & {
resource: string
Expand All @@ -11,10 +13,32 @@ export const RouteEnforcer = ({
action,
children
}: RouteEnforcerProps) => {
const intl = useIntl()
const { validate } = usePermissions()

if (!validate(resource, action)) {
redirect('/')
return (
<div className="flex h-full flex-col items-center justify-center">
<div className="flex flex-col justify-center gap-4 text-center">
<h1 className="text-3xl">
{intl.formatMessage({
id: 'notAuthorized.title',
defaultMessage: 'You are not authorized to access this page.'
})}
</h1>
<div className="flex justify-center">
<Link href="/">
<Button>
{intl.formatMessage({
id: 'notAuthorized.backToHome',
defaultMessage: 'Back to Home'
})}
</Button>
</Link>
</div>
</div>
</div>
)
}

return children
Expand Down

0 comments on commit 44cf689

Please sign in to comment.