Skip to content

Commit

Permalink
feat: expose projectId on login.status()
Browse files Browse the repository at this point in the history
  • Loading branch information
polomani authored and BugGambit committed Sep 10, 2019
1 parent 1b4a0f4 commit 00ab757
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 26 deletions.
1 change: 1 addition & 0 deletions src/__tests__/resources/login.integration.spec.ts
Expand Up @@ -15,6 +15,7 @@ describe('Login-api integration test', () => {
expect(status).toBeDefined();
expect(status!.project).toBeDefined();
expect(status!.user).toBeDefined();
expect(typeof status!.projectId).toBe('number');
});

test('not logged in', async () => {
Expand Down
3 changes: 2 additions & 1 deletion src/__tests__/resources/login.spec.ts
Expand Up @@ -17,6 +17,7 @@ import {
mockBaseUrl,
notLoggedInResponse,
project,
projectId,
} from '../testUtils';

describe('Login', () => {
Expand Down Expand Up @@ -123,12 +124,12 @@ describe('Login', () => {
describe('getIdInfo', () => {
const idInfo = {
project,
projectId,
user: 'user@example.com',
};
const successResponse = {
data: {
loggedIn: true,
projectId: 1,
...idInfo,
},
};
Expand Down
4 changes: 3 additions & 1 deletion src/resources/login.ts
Expand Up @@ -25,6 +25,7 @@ const LOGIN_IFRAME_NAME = 'cognite-js-sdk-auth-iframe';
const LOGIN_POPUP_NAME = 'cognite-js-sdk-auth-popup';

export interface IdInfo {
projectId: number;
project: string;
user: string;
}
Expand Down Expand Up @@ -124,13 +125,14 @@ export async function getIdInfo(
): Promise<null | IdInfo> {
try {
const response = await httpClient.get<any>('/login/status', { headers });
const { loggedIn, user, project } = response.data.data;
const { loggedIn, user, project, projectId } = response.data.data;
if (!loggedIn) {
return null;
}
return {
user,
project,
projectId,
};
} catch (err) {
if (err.status === 401) {
Expand Down
24 changes: 0 additions & 24 deletions src/utils/http/cdfHttpClient.ts
Expand Up @@ -86,25 +86,6 @@ export class CDFHttpClient extends RetryableHttpClient {
this.setDefaultHeader(AUTHORIZATION_HEADER, bearerString(token));
}

public async getIdInfo(headers: HttpHeaders): Promise<null | IdInfo> {
try {
const response = await this.get<any>('/login/status', { headers });
const { loggedIn, user, project } = response.data.data;
if (!loggedIn) {
return null;
}
return {
user,
project,
};
} catch (err) {
if (err.status === 401) {
return null;
}
throw err;
}
}

public set401ResponseHandler(handler: Response401Handler) {
this.response401Handler = handler;
}
Expand Down Expand Up @@ -168,11 +149,6 @@ export class CDFHttpClient extends RetryableHttpClient {
}
}

export interface IdInfo {
project: string;
user: string;
}

type Response401Handler = (
err: HttpError,
retry: () => void,
Expand Down

0 comments on commit 00ab757

Please sign in to comment.