feat: better way to detect initial account creation
This commit is contained in:
+29
-42
@@ -1,4 +1,4 @@
|
||||
import React, { useState } from 'react'
|
||||
import React from 'react'
|
||||
import { Admin, resolveBrowserLocale, Resource } from 'react-admin'
|
||||
import dataProvider from './dataProvider'
|
||||
import authProvider from './authProvider'
|
||||
@@ -19,48 +19,35 @@ const i18nProvider = polyglotI18nProvider(
|
||||
resolveBrowserLocale()
|
||||
)
|
||||
|
||||
const App = () => (
|
||||
<Admin
|
||||
theme={theme}
|
||||
customReducers={{ queue: playQueueReducer }}
|
||||
dataProvider={dataProvider}
|
||||
authProvider={authProvider}
|
||||
i18nProvider={i18nProvider}
|
||||
layout={Layout}
|
||||
loginPage={Login}
|
||||
>
|
||||
{(permissions) => [
|
||||
<Resource name="artist" {...artist} options={{ subMenu: 'library' }} />,
|
||||
<Resource name="album" {...album} options={{ subMenu: 'library' }} />,
|
||||
<Resource name="song" {...song} options={{ subMenu: 'library' }} />,
|
||||
permissions === 'admin' ? <Resource name="user" {...user} /> : null,
|
||||
<Player />
|
||||
]}
|
||||
</Admin>
|
||||
)
|
||||
const App = () => {
|
||||
try {
|
||||
const appConfig = JSON.parse(window.__APP_CONFIG__)
|
||||
|
||||
// TODO: This is a complicated way to force a first check for initial setup. A better way would be to send this info
|
||||
// set in the `window` object in the index.html
|
||||
const AppWrapper = () => {
|
||||
const [checked, setChecked] = useState(false)
|
||||
// This flags to the login process that it should create the first account instead
|
||||
if (appConfig.firstTime) {
|
||||
localStorage.setItem('initialAccountCreation', 'true')
|
||||
}
|
||||
} catch (e) {}
|
||||
|
||||
if (!checked) {
|
||||
dataProvider
|
||||
.getOne('keepalive', { id: new Date().getTime() })
|
||||
.then(() => setChecked(true))
|
||||
.catch((err) => {
|
||||
authProvider
|
||||
.checkError(err)
|
||||
.then(() => {
|
||||
setChecked(true)
|
||||
})
|
||||
.catch(() => {
|
||||
setChecked(true)
|
||||
})
|
||||
})
|
||||
return null
|
||||
}
|
||||
return <App />
|
||||
return (
|
||||
<Admin
|
||||
theme={theme}
|
||||
customReducers={{ queue: playQueueReducer }}
|
||||
dataProvider={dataProvider}
|
||||
authProvider={authProvider}
|
||||
i18nProvider={i18nProvider}
|
||||
layout={Layout}
|
||||
loginPage={Login}
|
||||
>
|
||||
{(permissions) => [
|
||||
<Resource name="artist" {...artist} options={{ subMenu: 'library' }} />,
|
||||
<Resource name="album" {...album} options={{ subMenu: 'library' }} />,
|
||||
<Resource name="song" {...song} options={{ subMenu: 'library' }} />,
|
||||
permissions === 'admin' ? <Resource name="user" {...user} /> : null,
|
||||
<Player />
|
||||
]}
|
||||
</Admin>
|
||||
)
|
||||
}
|
||||
|
||||
export default AppWrapper
|
||||
export default App
|
||||
|
||||
Reference in New Issue
Block a user