2020-08-26 15:44:50 -07:00
|
|
|
import { getApiRoot, ApiVersion } from '@datahub/utils/api/shared';
|
2019-08-31 20:51:14 -07:00
|
|
|
import { getJSON } from '@datahub/utils/api/fetcher';
|
2020-08-26 15:44:50 -07:00
|
|
|
import { ICorpUserInfo } from '@datahub/metadata-types/types/entity/person/person-entity';
|
2020-08-28 10:31:15 -07:00
|
|
|
import { IUser } from '@datahub/metadata-types/types/common/user';
|
2019-08-31 20:51:14 -07:00
|
|
|
|
2020-08-28 10:31:15 -07:00
|
|
|
const currentUserUrl = `${getApiRoot(ApiVersion.v2)}/user/me`;
|
2019-08-31 20:51:14 -07:00
|
|
|
|
|
|
|
/**
|
2020-08-26 15:44:50 -07:00
|
|
|
* Requests the currently logged in user and returns that user
|
2019-08-31 20:51:14 -07:00
|
|
|
*/
|
2020-08-26 15:44:50 -07:00
|
|
|
export const currentUser = (): Promise<ICorpUserInfo> => getJSON({ url: currentUserUrl });
|
2020-08-28 10:31:15 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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);
|