diff --git a/public/config.json b/public/config.json
deleted file mode 100644
index 1fd4a16..0000000
--- a/public/config.json
+++ /dev/null
@@ -1,4 +0,0 @@
-{
- "default_hs_url": "http://localhost:8008",
- "default_is_url": "http://localhost:8008/"
-}
diff --git a/public/index.html b/public/index.html
index 043c069..36001f0 100644
--- a/public/index.html
+++ b/public/index.html
@@ -24,7 +24,7 @@
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
-
React App
+ Watcha admin
diff --git a/src/App.js b/src/App.js
index 49c7f20..10783b5 100644
--- a/src/App.js
+++ b/src/App.js
@@ -2,7 +2,7 @@ import React, { Component } from 'react';
import logo from './images/logo.svg';
import './App.css';
import AdminHome from './AdminHome.js';
-import {Button, FormGroup, FormControl, Col, Form, Grid, Row} from 'react-bootstrap';
+import { Button, FormGroup, FormControl, Col, Form, Grid, Row } from 'react-bootstrap';
class App extends Component {
@@ -17,60 +17,63 @@ class App extends Component {
};
}
- onConnection = async () => {
- const self = this;
- const userName = this.state.userName;
- const password = this.state.password;
+ onConnection = async () => {
+ const self = this;
+ const userName = this.state.userName;
+ const password = this.state.password;
- try {
- await this.getserverName();
- // XHR POST to login
- const loginRequest = await fetch( this.state.homeserver + '_matrix/client/r0/login', {
- method: 'POST',
- body: JSON.stringify({
- 'initial_device_display_name': 'Web setup account',
- 'user': userName,
- 'password': password,
- 'type': 'm.login.password',
- }),
- headers: {
- 'Content-Type': 'application/json',
- 'Accept': 'application/json',
- },
- });
- const loginData = JSON.parse(await loginRequest.text());
- if (loginData['access_token']) {
- self.setState({accessToken: loginData['access_token']});
- return this.state.accessToken;
- }
- } catch (e) {
- console.log('error: ' + e);
+ try {
+ const path = await this.getserverName() + '_matrix/client/r0/login';
+ // XHR POST to login
+ const loginRequest = await fetch(path, {
+ method: 'POST',
+ body: JSON.stringify({
+ 'initial_device_display_name': 'Web setup account',
+ 'user': userName,
+ 'password': password,
+ 'type': 'm.login.password',
+ }),
+ headers: {
+ 'Content-Type': 'application/json',
+ 'Accept': 'application/json',
+ },
+ });
+ const loginData = JSON.parse(await loginRequest.text());
+ if (loginData['access_token']) {
+ self.setState({ accessToken: loginData['access_token'] });
+ return this.state.accessToken;
+ } else {
+ throw new Error('no access token');
+ }
+ } catch (e) {
+ console.log('error: ' + e);
- return;
- }
- }
+ return;
+ }
+ }
+
+ getserverName = async () => {
+ let coreUrl = '';
+ try {
+ const configRequest = await fetch('/config.json');
+ const configData = JSON.parse(await configRequest.text());
+ coreUrl = configData['default_hs_url'];
+ if (!coreUrl) throw new Error('could not get coreUrl');
+ } catch (e) {
+ console.log('coreUrl error = ' + e);
+ return;
+ }
+ console.log('coreURL = ' + coreUrl);
+ this.setState({ homeserver: coreUrl + '/' });
+ return coreUrl + '/';
+ }
- getserverName = async () => {
- let coreUrl = '';
- const currentpage = window.location.protocol+'//'+window.location.hostname+'/';
- try {
- const configRequest = await fetch(currentpage+'/config.json');
- const configData = JSON.parse(await configRequest.text());
- coreUrl = configData['default_hs_url'];
- if (!coreUrl) throw new Error('could not get coreUrl');
- } catch (e) {
- console.log('error: ' + e);
- return;
- }
- console.log(coreUrl);
- this.setState({homeserver: coreUrl+'/'});
- }
onNameChange = (evt) => {
- this.setState({userName: evt.target.value});
+ this.setState({ userName: evt.target.value });
}
onPasswordChange = (evt) => {
- this.setState({password: evt.target.value});
+ this.setState({ password: evt.target.value });
}
render() {
@@ -82,7 +85,7 @@ class App extends Component {
-
+