Skip to content

🎧 Your Personal Streaming Service

Consolidate UI configuration in one place, allowing it to be overridden from the server

Deluana0f389fc3e23
diff --git a/ui/src/authProvider.js b/ui/src/authProvider.js
index cc6bc0fd4..58e68bb32 100644
--- a/ui/src/authProvider.js
+++ b/ui/src/authProvider.js
@@ -1,11 +1,12 @@
import jwtDecode from 'jwt-decode'
import md5 from 'md5-hex'
import baseUrl from './utils/baseUrl'
+import config from './config'
const authProvider = {
login: ({ username, password }) => {
let url = baseUrl('/app/login')
- if (localStorage.getItem('initialAccountCreation')) {
+ if (config.firstTime) {
url = baseUrl('/app/createAdmin')
}
const request = new Request(url, {
diff --git a/ui/src/config.js b/ui/src/config.js
new file mode 100644
index 000000000..01de2b2d2
--- /dev/null
+++ b/ui/src/config.js
@@ -0,0 +1,20 @@
+const defaultConfig = {
+ firstTime: false,
+ baseURL: '',
+ loginBackgroundURL: 'https://source.unsplash.com/random/1600x900?music'
+}
+
+let config
+
+try {
+ const appConfig = JSON.parse(window.__APP_CONFIG__)
+
+ config = {
+ ...defaultConfig,
+ ...appConfig
+ }
+} catch (e) {
+ config = defaultConfig
+}
+
+export default config
diff --git a/ui/src/layout/Login.js b/ui/src/layout/Login.js
index 64acc94c1..1825a4cb5 100644
--- a/ui/src/layout/Login.js
+++ b/ui/src/layout/Login.js
@@ -15,6 +15,7 @@ import LockIcon from '@material-ui/icons/Lock'
import { Notification, useLogin, useNotify, useTranslate } from 'react-admin'
import LightTheme from '../themes/light'
+import config from '../config'
const useStyles = makeStyles((theme) => ({
main: {
@@ -23,7 +24,7 @@ const useStyles = makeStyles((theme) => ({
minHeight: '100vh',
alignItems: 'center',
justifyContent: 'flex-start',
- background: 'url(https://source.unsplash.com/random/1600x900?music)',
+ background: `url(${config.loginBackgroundURL})`,
backgroundRepeat: 'no-repeat',
backgroundSize: 'cover',
backgroundPosition: 'center'
@@ -253,7 +254,7 @@ const Login = ({ location }) => {
return errors
}
- if (localStorage.getItem('initialAccountCreation') === 'true') {
+ if (config.firstTime) {
return (
<FormSignUp
handleSubmit={handleSubmit}
diff --git a/ui/src/utils/baseUrl.js b/ui/src/utils/baseUrl.js
index d19482cc3..92c29fb83 100644
--- a/ui/src/utils/baseUrl.js
+++ b/ui/src/utils/baseUrl.js
@@ -1,5 +1,7 @@
+import config from '../config'
+
const baseUrl = (path) => {
- const base = localStorage.getItem('baseURL') || ''
+ const base = config.baseURL || ''
const parts = [base]
parts.push(path.replace(/^\//, ''))
return parts.join('/')