feat: introducing Auth for admin dashboard (HBE-138) (#32)
This commit is contained in:
19
packages/hoppscotch-sh-admin/src/modules/admin.ts
Normal file
19
packages/hoppscotch-sh-admin/src/modules/admin.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { auth } from '~/helpers/auth';
|
||||
import { HoppModule } from '.';
|
||||
|
||||
const isAdmin = () => {
|
||||
const user = auth.getCurrentUser();
|
||||
return user ? user.isAdmin : false;
|
||||
};
|
||||
|
||||
export default <HoppModule>{
|
||||
onBeforeRouteChange(to, from, next) {
|
||||
if (to.name !== 'index' && !isAdmin()) {
|
||||
next({ name: 'index' });
|
||||
} else if (to.name === 'index' && isAdmin()) {
|
||||
next({ name: 'dashboard' });
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user