/*
 * Copyright (c) 2023-2025 Datalayer, Inc.
 * Distributed under the terms of the Modified BSD License.
 */
import { useIAMStore } from '../state/index.js';
const LOGIN_HREF = '/login';
export const useUser = (role) => {
    const { user } = useIAMStore();
    if (role) {
        if (!user?.roles.includes(role.handle)) {
            console.log(`User should have role ${role.handle} - Forcing navigation to login page...`);
            window.location.href = LOGIN_HREF;
            throw new Error(`User should have role ${role.handle}`);
        }
    }
    if (!user) {
        console.log('No user found... Forcing navigation to /login');
        window.location.href = LOGIN_HREF;
    }
    return user;
};
export default useUser;
