diff --git a/CHANGELOG.md b/CHANGELOG.md
index c873ee04..30e3a24c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -71,7 +71,13 @@ The following log documentes the history of the browser extensions project
### [Unreleased]
-#### Fixed
+N/A
+
+### 2.0.0 - 2019-10-29
+
+- Allow to customize API and web URLs (#285)
+
+### 1.1.1 - 2019-10-02
- Fix failing requests (#263)
diff --git a/Makefile b/Makefile
index b4d32b79..d32d03ef 100644
--- a/Makefile
+++ b/Makefile
@@ -171,3 +171,9 @@ clean:
@rm -rf build
@rm -rf web/public
.PHONY: clean
+
+clean-dep:
+ @rm -rf ./web/node_modules
+ @rm -rf ./jslib/node_modules
+ @rm -rf ./browser/node_modules
+.PHONY: clean-dep
diff --git a/browser/package.json b/browser/package.json
index 2d4e4b45..3a578e07 100644
--- a/browser/package.json
+++ b/browser/package.json
@@ -12,7 +12,7 @@
},
"author": "Monomax Software Pty Ltd",
"license": "GPL-3.0-or-later",
- "version": "1.1.1",
+ "version": "2.0.0",
"dependencies": {
"classnames": "^2.2.5",
"lodash": "^4.17.15",
diff --git a/browser/src/scripts/components/App.tsx b/browser/src/scripts/components/App.tsx
index a97ac662..47fec645 100644
--- a/browser/src/scripts/components/App.tsx
+++ b/browser/src/scripts/components/App.tsx
@@ -19,13 +19,15 @@
import React, { useState, useEffect } from 'react';
import classnames from 'classnames';
-import services from '../utils/services';
-import { resetSettings } from '../store/settings/actions';
+import initServices from '../utils/services';
+import { logout } from '../store/auth/actions';
+import { AuthState } from '../store/auth/types';
import { useSelector, useDispatch } from '../store/hooks';
import Header from './Header';
import Home from './Home';
import Menu from './Menu';
import Success from './Success';
+import Settings from './Settings';
import Composer from './Composer';
interface Props {}
@@ -34,45 +36,58 @@ function renderRoutes(path: string, isLoggedIn: boolean) {
switch (path) {
case '/success':
return ;
- case '/':
+ case '/': {
if (isLoggedIn) {
return ;
}
return ;
+ }
+ case '/settings': {
+ return ;
+ }
default:
return
Not found
;
}
}
+// useCheckSessionValid ensures that the current session is valid
+function useCheckSessionValid(auth: AuthState) {
+ const dispatch = useDispatch();
+
+ useEffect(() => {
+ // if session is expired, clear it
+ const now = Math.round(new Date().getTime() / 1000);
+ if (auth.sessionKey && auth.sessionKeyExpiry < now) {
+ dispatch(logout());
+ }
+ }, [dispatch, auth.sessionKey, auth.sessionKeyExpiry]);
+}
+
const App: React.FunctionComponent = () => {
const [isMenuOpen, setIsMenuOpen] = useState(false);
const [errMsg, setErrMsg] = useState('');
const dispatch = useDispatch();
- const { path, settings } = useSelector(state => {
+ const { path, auth, settings } = useSelector(state => {
return {
path: state.location.path,
+ auth: state.auth,
settings: state.settings
};
});
- useEffect(() => {
- // if session is expired, clear it
- const now = Math.round(new Date().getTime() / 1000);
- if (settings.sessionKey && settings.sessionKeyExpiry < now) {
- dispatch(resetSettings());
- }
- }, [dispatch]);
+ useCheckSessionValid(auth);
- const isLoggedIn = Boolean(settings.sessionKey);
+ const isLoggedIn = Boolean(auth.sessionKey);
const toggleMenu = () => {
setIsMenuOpen(!isMenuOpen);
};
+
const handleLogout = async (done?: Function) => {
try {
- await services.users.signout();
- dispatch(resetSettings());
+ await initServices(settings.apiUrl).users.signout();
+ dispatch(logout());
if (done) {
done();
diff --git a/browser/src/scripts/components/Composer.tsx b/browser/src/scripts/components/Composer.tsx
index 7d961020..47fba925 100644
--- a/browser/src/scripts/components/Composer.tsx
+++ b/browser/src/scripts/components/Composer.tsx
@@ -20,7 +20,7 @@ import React, { useState, useEffect, useRef } from 'react';
import classnames from 'classnames';
import { KEYCODE_ENTER } from 'jslib/helpers/keyboard';
-import services from '../utils/services';
+import initServices from '../utils/services';
import BookSelector from './BookSelector';
import Flash from './Flash';
import { useSelector, useDispatch } from '../store/hooks';
@@ -88,16 +88,19 @@ const Composer: React.FunctionComponent = () => {
const [contentRef, setContentEl] = useState(null);
const [bookSelectorRef, setBookSelectorEl] = useState(null);
- const { composer, settings } = useSelector(state => {
+ const { composer, settings, auth } = useSelector(state => {
return {
composer: state.composer,
- settings: state.settings
+ settings: state.settings,
+ auth: state.auth
};
});
const handleSubmit = async e => {
e.preventDefault();
+ const services = initServices(settings.apiUrl);
+
setSubmitting(true);
try {
@@ -109,7 +112,7 @@ const Composer: React.FunctionComponent = () => {
},
{
headers: {
- Authorization: `Bearer ${settings.sessionKey}`
+ Authorization: `Bearer ${auth.sessionKey}`
}
}
);
@@ -126,7 +129,7 @@ const Composer: React.FunctionComponent = () => {
},
{
headers: {
- Authorization: `Bearer ${settings.sessionKey}`
+ Authorization: `Bearer ${auth.sessionKey}`
}
}
);
@@ -176,7 +179,7 @@ const Composer: React.FunctionComponent = () => {
return (