UNPKG

@alauda/doom

Version:

Doctor Doom making docs.

38 lines (37 loc) 1.17 kB
import { decodeUrl } from 'ab64'; import siteData from 'virtual-site-data'; export const setLocalStorage = (key, value) => { if (value == null) { localStorage.removeItem(key); } else { localStorage.setItem(key, value); } }; export const getAuthInfoFromToken = (token) => { if (!token) { return; } let authTokenInfo; try { authTokenInfo = JSON.parse(decodeUrl(token.split('.')[1])); } catch (err) { console.error('jwt decode failed:', err); return; } return { type: authTokenInfo.tenant_type, tenant: authTokenInfo.tenant_id, user: { id: authTokenInfo.user_id, name: authTokenInfo.preferred_username || authTokenInfo.email, type: authTokenInfo.user_type, internal: authTokenInfo.user_type === 'serviceuser', }, }; }; export const isLoggedIn = (authInfo) => Boolean(authInfo?.detail); export const isIoSite = () => siteData.base.startsWith('/russian/') || location.hostname.endsWith('.alauda.io'); export const getCloudOrigin = () => `https://cloud.alauda.${isIoSite() ? 'io' : 'cn'}`;