Skip to content

Instantly share code, notes, and snippets.

@javierd79
Last active October 2, 2022 18:42
Show Gist options
  • Save javierd79/e9be04fbd3398f2b6308ba3608eb4781 to your computer and use it in GitHub Desktop.
Save javierd79/e9be04fbd3398f2b6308ba3608eb4781 to your computer and use it in GitHub Desktop.
control access in an APP with React
const permissions = {
Admin: ['/', '/users'],
undefined: ['/login'],
null: ['/login'],
};
const initialState = {
status: false,
};
export const protectedRoutes = (path) => {
permissions['Admin'].includes(path) && initialState.status
? console.log('Has access')
: console.log(`Unauthorized`)
};
protectedRoutes('/');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment