mirror of
https://github.com/freqtrade/frequi.git
synced 2024-11-27 05:25:17 +00:00
Add typings to telegram userService calls
This commit is contained in:
parent
457b5f52f5
commit
5858f4df6b
|
@ -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 AUTH_LOGIN_INFO = 'auth_login_info';
|
||||||
const APIBASE = '/api/v1';
|
const APIBASE = '/api/v1';
|
||||||
|
@ -120,19 +120,19 @@ export class UserService {
|
||||||
|
|
||||||
public async login(auth: AuthPayload) {
|
public async login(auth: AuthPayload) {
|
||||||
// Login using username / password
|
// Login using username / password
|
||||||
const result = await axios.post(
|
const { data } = await axios.post<{}, AxiosResponse<AuthResponse>>(
|
||||||
`${auth.url}/api/v1/token/login`,
|
`${auth.url}/api/v1/token/login`,
|
||||||
{},
|
{},
|
||||||
{
|
{
|
||||||
auth: { ...auth },
|
auth: { ...auth },
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
if (result.data.access_token && result.data.refresh_token) {
|
if (data.access_token && data.refresh_token) {
|
||||||
const obj: AuthStorage = {
|
const obj: AuthStorage = {
|
||||||
botName: auth.botName,
|
botName: auth.botName,
|
||||||
apiUrl: auth.url,
|
apiUrl: auth.url,
|
||||||
accessToken: result.data.access_token || '',
|
accessToken: data.access_token || '',
|
||||||
refreshToken: result.data.refresh_token || '',
|
refreshToken: data.refresh_token || '',
|
||||||
autoRefresh: true,
|
autoRefresh: true,
|
||||||
};
|
};
|
||||||
this.storeLoginInfo(obj);
|
this.storeLoginInfo(obj);
|
||||||
|
@ -144,7 +144,7 @@ export class UserService {
|
||||||
const token = this.getRefreshToken();
|
const token = this.getRefreshToken();
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
axios
|
axios
|
||||||
.post(
|
.post<{}, AxiosResponse<AuthResponse>>(
|
||||||
`${this.getAPIUrl()}${APIBASE}/token/refresh`,
|
`${this.getAPIUrl()}${APIBASE}/token/refresh`,
|
||||||
{},
|
{},
|
||||||
{
|
{
|
||||||
|
|
|
@ -5,6 +5,11 @@ export interface AuthPayload {
|
||||||
password: string;
|
password: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface AuthResponse {
|
||||||
|
access_token?: string;
|
||||||
|
refresh_token?: string;
|
||||||
|
}
|
||||||
|
|
||||||
export interface AuthStorage {
|
export interface AuthStorage {
|
||||||
botName: string;
|
botName: string;
|
||||||
apiUrl: string;
|
apiUrl: string;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user