Menu

Post image 1
Post image 2
1 / 2
0

Stop copy-pasting your React route protection. Here's a better way.

DEV Community·Аскольд Астахов·21 days ago
#fM4VIjnd
#react#javascript#frontend#webdev#roles#user
Reading 0:00
15s threshold

On every project you need to protect routes. Some are for authenticated users only, some for admins, some for guests only. You write a PrivateRoute . Then a role check hook. Then a HasAccess component. You move to the next project — and write it all again. The logic is always the same. The implementation is always different. react-protected standardizes this. You describe what each route requires. The library checks access and redirects. Two packages @react-protected/core — framework-agnostic guard logic. No dependency on React or any router. @react-protected/react-router — adapter for React Router. Two styles supported: config-based and JSX.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More