chore: get api key from coookie

This commit is contained in:
Sebastian Velez
2023-02-15 12:25:19 -05:00
parent ffd2a48b29
commit 00209ec96f
5 changed files with 35 additions and 4 deletions

View File

@@ -4,7 +4,7 @@ import axios, { AxiosResponse } from 'axios';
import moment from 'moment';
import browser, { Tabs } from 'webextension-polyfill';
import { IDBPDatabase, openDB } from 'idb';
import { AxiosUserResponse, User } from '../types/user';
import { ApiKeyPayload, AxiosUserResponse, User } from '../types/user';
import config from '../config/config';
import { SummariesPayload, GrandTotal } from '../types/summaries';
import changeExtensionState from '../utils/changeExtensionState';
@@ -63,6 +63,22 @@ class WakaTimeCore {
return summariesAxiosPayload.data.data[0].grand_total;
}
/**
* Fetches the api token for logged users in wakatime website
*
* @returns {*}
*/
async fetchApiKey(): Promise<string> {
try {
const apiKeyResponse: AxiosResponse<ApiKeyPayload> = await axios.post(
`${config.currentUserApiUrl}/get_api_key`,
);
return apiKeyResponse.data.data.api_key;
} catch (err: unknown) {
return '';
}
}
/**
* Checks if the user is logged in.
*