Add typings to telegram userService calls

This commit is contained in:
Matthias 2021-10-05 06:57:09 +02:00
parent 457b5f52f5
commit 5858f4df6b
2 changed files with 12 additions and 7 deletions

View File

@ -1,6 +1,6 @@
import axios from 'axios';
import axios, { AxiosResponse } from 'axios';
import { AuthPayload, BotDescriptors, AuthStorage, AuthStorageMulti } from '@/types';
import { AuthPayload, AuthResponse, BotDescriptors, AuthStorage, AuthStorageMulti } from '@/types';
const AUTH_LOGIN_INFO = 'auth_login_info';
const APIBASE = '/api/v1';
@ -120,19 +120,19 @@ export class UserService {
public async login(auth: AuthPayload) {
// Login using username / password
const result = await axios.post(
const { data } = await axios.post<{}, AxiosResponse<AuthResponse>>(
`${auth.url}/api/v1/token/login`,
{},
{
auth: { ...auth },
},
);
if (result.data.access_token && result.data.refresh_token) {
if (data.access_token && data.refresh_token) {
const obj: AuthStorage = {
botName: auth.botName,
apiUrl: auth.url,
accessToken: result.data.access_token || '',
refreshToken: result.data.refresh_token || '',
accessToken: data.access_token || '',
refreshToken: data.refresh_token || '',
autoRefresh: true,
};
this.storeLoginInfo(obj);
@ -144,7 +144,7 @@ export class UserService {
const token = this.getRefreshToken();
return new Promise((resolve, reject) => {
axios
.post(
.post<{}, AxiosResponse<AuthResponse>>(
`${this.getAPIUrl()}${APIBASE}/token/refresh`,
{},
{

View File

@ -5,6 +5,11 @@ export interface AuthPayload {
password: string;
}
export interface AuthResponse {
access_token?: string;
refresh_token?: string;
}
export interface AuthStorage {
botName: string;
apiUrl: string;