chore: configure base url (#179)

* chore: set base api url

* chore: change config varibales names

* chore: rename env var

* chore: set base url to match wakatime cli usage
This commit is contained in:
Juan Sebastian velez Posada
2023-03-28 17:50:32 -05:00
committed by GitHub
parent 1e9e233066
commit c2ead5149d
9 changed files with 87 additions and 37 deletions

View File

@@ -1,7 +1,8 @@
import { createSlice, createAsyncThunk } from '@reduxjs/toolkit';
import { createAsyncThunk, createSlice } from '@reduxjs/toolkit';
import axios, { AxiosResponse } from 'axios';
import { CurrentUser, User, UserPayload } from '../types/user';
import browser from 'webextension-polyfill';
import config from '../config/config';
import { CurrentUser, User, UserPayload } from '../types/user';
interface setUserAction {
payload: User | undefined;
@@ -14,9 +15,16 @@ export const name: NameType = 'currentUser';
export const fetchCurrentUser = createAsyncThunk<User, string>(
`[${name}]`,
async (api_key = '') => {
const userPayload: AxiosResponse<UserPayload> = await axios.get(config.currentUserApiUrl, {
params: { api_key },
const items = await browser.storage.sync.get({
apiUrl: config.apiUrl,
currentUserApiEndPoint: config.currentUserApiEndPoint,
});
const userPayload: AxiosResponse<UserPayload> = await axios.get(
`${items.apiUrl}${items.currentUserApiEndPoint}`,
{
params: { api_key },
},
);
return userPayload.data.data;
},
);