UNPKG

@datalayer/core

Version:

[![Datalayer](https://assets.datalayer.tech/datalayer-25.svg)](https://datalayer.io)

23 lines (22 loc) 731 B
/* * Copyright (c) 2023-2025 Datalayer, Inc. * Distributed under the terms of the Modified BSD License. */ import { useIAMStore } from '../state'; 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;