Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | // import React from 'react' const getCurrentUser = () => { const userStr = localStorage.getItem('user') if (!userStr) return null try { return JSON.parse(userStr) } catch { return null } } const AuthCheck = ({ rights, children }) => { const user = getCurrentUser() if (!user) return null const userRights = user.rights || [] const requiredRights = Array.isArray(rights) ? rights : [rights] const hasRight = requiredRights.some((r) => userRights.includes(r)) if (!hasRight) return null return <>{children}</> } export default AuthCheck |