mirror of
https://github.com/sct/overseerr.git
synced 2025-12-27 16:46:29 +01:00
* build: bump deps and add some new eslint rules * refactor: run eslint --fix on code to convert to type imports where possible
21 lines
569 B
TypeScript
21 lines
569 B
TypeScript
import { useRouter } from 'next/router';
|
|
import { useEffect } from 'react';
|
|
import type { Permission, PermissionCheckOptions } from './useUser';
|
|
import { useUser } from './useUser';
|
|
|
|
const useRouteGuard = (
|
|
permission: Permission | Permission[],
|
|
options?: PermissionCheckOptions
|
|
): void => {
|
|
const router = useRouter();
|
|
const { user, hasPermission } = useUser();
|
|
|
|
useEffect(() => {
|
|
if (user && !hasPermission(permission, options)) {
|
|
router.push('/');
|
|
}
|
|
}, [user, permission, router, hasPermission, options]);
|
|
};
|
|
|
|
export default useRouteGuard;
|