mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-10-16 03:51:31 +08:00

Enhance platform to handle cloud, self-hosted, community, and enterprise user types with tailored routing, error handling, and feature access.
37 lines
1.0 KiB
TypeScript
37 lines
1.0 KiB
TypeScript
import { AxiosError } from 'axios';
|
|
import { useAppContext } from 'providers/App/App';
|
|
import { LicensePlatform } from 'types/api/licensesV3/getActive';
|
|
|
|
export const useGetTenantLicense = (): {
|
|
isCloudUser: boolean;
|
|
isEnterpriseSelfHostedUser: boolean;
|
|
isCommunityUser: boolean;
|
|
isCommunityEnterpriseUser: boolean;
|
|
} => {
|
|
const { activeLicenseV3, activeLicenseV3FetchError } = useAppContext();
|
|
|
|
const responsePayload = {
|
|
isCloudUser: activeLicenseV3?.platform === LicensePlatform.CLOUD || false,
|
|
isEnterpriseSelfHostedUser:
|
|
activeLicenseV3?.platform === LicensePlatform.SELF_HOSTED || false,
|
|
isCommunityUser: false,
|
|
isCommunityEnterpriseUser: false,
|
|
};
|
|
|
|
if (
|
|
activeLicenseV3FetchError &&
|
|
(activeLicenseV3FetchError as AxiosError)?.response?.status === 404
|
|
) {
|
|
responsePayload.isCommunityEnterpriseUser = true;
|
|
}
|
|
|
|
if (
|
|
activeLicenseV3FetchError &&
|
|
(activeLicenseV3FetchError as AxiosError)?.response?.status === 501
|
|
) {
|
|
responsePayload.isCommunityUser = true;
|
|
}
|
|
|
|
return responsePayload;
|
|
};
|