Last active
October 2, 2022 18:42
-
-
Save javierd79/e9be04fbd3398f2b6308ba3608eb4781 to your computer and use it in GitHub Desktop.
control access in an APP with React
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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