mirror of
https://github.com/freqtrade/frequi.git
synced 2024-11-21 23:53:52 +00:00
Have user input login-url
This commit is contained in:
parent
37188543d8
commit
6f84b18130
|
@ -1,5 +1,6 @@
|
|||
import axios from 'axios';
|
||||
import { apiBase } from '../store/modules/config';
|
||||
|
||||
export const apiBase = '/api/v1';
|
||||
|
||||
export const apiStore = { store: null };
|
||||
|
||||
|
@ -37,3 +38,16 @@ api.interceptors.response.use(
|
|||
// // return Promise.reject(err);
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
export function setBaseUrl(baseURL) {
|
||||
if (baseURL === null) {
|
||||
// Reset to "local" baseurl
|
||||
api.defaults.baseURL = apiBase;
|
||||
} else if (!baseURL.endsWith(apiBase)) {
|
||||
api.defaults.baseURL = `${baseURL}${apiBase}`;
|
||||
} else {
|
||||
api.defaults.baseURL = `${baseURL}`;
|
||||
}
|
||||
// Do some more testing here ?
|
||||
}
|
||||
|
|
|
@ -1,13 +1,10 @@
|
|||
import Vue from 'vue';
|
||||
import Vuex from 'vuex';
|
||||
import axios from 'axios';
|
||||
|
||||
import ftbotModule from './modules/ftbot';
|
||||
import userModule from './modules/user';
|
||||
import alertsModule from './modules/alerts';
|
||||
|
||||
import { apiBase } from './modules/config';
|
||||
|
||||
Vue.use(Vuex);
|
||||
|
||||
export default new Vuex.Store({
|
||||
|
@ -25,12 +22,6 @@ export default new Vuex.Store({
|
|||
},
|
||||
},
|
||||
actions: {
|
||||
ping({ commit }) {
|
||||
axios
|
||||
.get(`${apiBase}/ping`)
|
||||
.then((result) => commit('setPing', result.data))
|
||||
.catch(console.error);
|
||||
},
|
||||
refreshAll({ dispatch }) {
|
||||
dispatch('refreshFrequent');
|
||||
dispatch('refreshSlow');
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
const apiBase = '/api/v1';
|
||||
|
||||
module.exports = {
|
||||
apiBase,
|
||||
};
|
|
@ -1,4 +1,4 @@
|
|||
import { api } from '../../shared/apiService';
|
||||
import { api } from '@/shared/apiService';
|
||||
|
||||
export default {
|
||||
namespaced: true,
|
||||
|
@ -54,6 +54,12 @@ export default {
|
|||
},
|
||||
},
|
||||
actions: {
|
||||
ping({ commit }) {
|
||||
api
|
||||
.get('/ping')
|
||||
.then((result) => commit('setPing', result.data))
|
||||
.catch(console.error);
|
||||
},
|
||||
getTrades({ commit }) {
|
||||
console.log('fetching trades');
|
||||
return api
|
||||
|
|
|
@ -1,12 +1,16 @@
|
|||
import axios from 'axios';
|
||||
|
||||
import { apiBase } from './config';
|
||||
import { apiBase, setBaseUrl } from '@/shared/apiService';
|
||||
|
||||
const AUTH_REF_TOKEN = 'auth_ref_token';
|
||||
const AUTH_ACCESS_TOKEN = 'auth_access_token';
|
||||
const AUTH_API_URL = 'auth_api_url';
|
||||
|
||||
const initAccessToken = JSON.parse(localStorage.getItem(AUTH_ACCESS_TOKEN));
|
||||
|
||||
// Construct the api as "inserted URL" + /api/v1
|
||||
setBaseUrl(`${JSON.parse(localStorage.getItem(AUTH_API_URL))}`);
|
||||
|
||||
export default {
|
||||
namespaced: true,
|
||||
state: {
|
||||
|
@ -28,6 +32,10 @@ export default {
|
|||
},
|
||||
},
|
||||
mutations: {
|
||||
setAPIUrl(state, apiurl) {
|
||||
localStorage.setItem(AUTH_API_URL, JSON.stringify(apiurl));
|
||||
setBaseUrl(apiurl);
|
||||
},
|
||||
setAccessTokens(state, token) {
|
||||
localStorage.setItem(AUTH_ACCESS_TOKEN, JSON.stringify(token));
|
||||
state.accessToken = token;
|
||||
|
@ -45,18 +53,21 @@ export default {
|
|||
console.log('Logging out');
|
||||
localStorage.removeItem(AUTH_REF_TOKEN);
|
||||
localStorage.removeItem(AUTH_ACCESS_TOKEN);
|
||||
localStorage.removeItem(AUTH_API_URL);
|
||||
|
||||
state.auth = null;
|
||||
state.loggedIn = false;
|
||||
setBaseUrl(null);
|
||||
},
|
||||
},
|
||||
actions: {
|
||||
login({ commit }, auth) {
|
||||
commit('setAPIUrl', auth.url);
|
||||
// Login using username / password
|
||||
console.log(auth);
|
||||
axios
|
||||
.post(
|
||||
`${apiBase}/token/login`,
|
||||
`${auth.url}${apiBase}/token/login`,
|
||||
{},
|
||||
{
|
||||
auth: { ...auth },
|
||||
|
|
|
@ -10,10 +10,24 @@
|
|||
@ok="handleOk"
|
||||
>
|
||||
<form ref="form" @submit.stop.prevent="handleSubmit">
|
||||
<b-form-group
|
||||
:state="urlState"
|
||||
label="API Url"
|
||||
label-for="url-input"
|
||||
invalid-feedback="API Url required"
|
||||
>
|
||||
<b-form-input
|
||||
id="url-input"
|
||||
v-model="auth.url"
|
||||
:state="nameState"
|
||||
@keydown.enter.native="handleOk"
|
||||
required
|
||||
></b-form-input>
|
||||
</b-form-group>
|
||||
<b-form-group
|
||||
:state="nameState"
|
||||
label="Username"
|
||||
label-for="name-input"
|
||||
label-for="username-input"
|
||||
invalid-feedback="Name is required"
|
||||
>
|
||||
<b-form-input
|
||||
|
@ -50,10 +64,12 @@ export default {
|
|||
data() {
|
||||
return {
|
||||
auth: {
|
||||
url: 'http://localhost:8080',
|
||||
username: '',
|
||||
password: '',
|
||||
},
|
||||
nameState: null,
|
||||
urlState: null,
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
|
|
Loading…
Reference in New Issue
Block a user