19 lines
888 B
TypeScript
Raw Normal View History

import { getApiRoot, ApiVersion } from '@datahub/utils/api/shared';
2019-08-31 20:51:14 -07:00
import { getJSON } from '@datahub/utils/api/fetcher';
import { ICorpUserInfo } from '@datahub/metadata-types/types/entity/person/person-entity';
import { IUser } from '@datahub/metadata-types/types/common/user';
2019-08-31 20:51:14 -07:00
const currentUserUrl = `${getApiRoot(ApiVersion.v2)}/user/me`;
2019-08-31 20:51:14 -07:00
/**
* Requests the currently logged in user and returns that user
2019-08-31 20:51:14 -07:00
*/
export const currentUser = (): Promise<ICorpUserInfo> => getJSON({ url: currentUserUrl });
/**
* Because the open source midtier is currently lagging behind, we need to have a handler for the previous /user/me
* endpoint as otherwise it causes an issue with logging in on the open source frontend
*/
export const currentUserDeprecated = (): Promise<IUser> =>
getJSON({ url: `${getApiRoot(ApiVersion.v1)}/user/me` }).then(({ user }: { user: IUser }): IUser => user);