diff options
| author | JP Dillingham <jpdillingham@gmail.com> | 2022-02-18 09:58:58 -0600 |
|---|---|---|
| committer | JP Dillingham <jpdillingham@gmail.com> | 2022-02-18 09:58:58 -0600 |
| commit | 14b2b5fbe01fb9eb58eafd6441f9306f8ce73482 (patch) | |
| tree | 396279be8112a619c1dd0ac07e4861f5a1351b73 /src | |
| parent | fccc9c6440af11fd400f3d1dee243d2d18ea1651 (diff) | |
| download | slskd-14b2b5fbe01fb9eb58eafd6441f9306f8ce73482.tar.gz | |
re-initialize on login
Diffstat (limited to 'src')
| -rw-r--r-- | src/web/src/components/App.js | 66 |
1 files changed, 34 insertions, 32 deletions
diff --git a/src/web/src/components/App.js b/src/web/src/components/App.js index 35ef736f..3a22e0c8 100644 --- a/src/web/src/components/App.js +++ b/src/web/src/components/App.js @@ -48,48 +48,50 @@ class App extends Component { }; init = async () => { - try { - const securityEnabled = await session.getSecurityEnabled(); + this.setState({ initialized: false }, async () => { + try { + const securityEnabled = await session.getSecurityEnabled(); + + if (!securityEnabled) { + console.debug('application security is not enabled, per api call') + session.enablePassthrough() + } + + if (await session.check()) { + const appHub = createApplicationHubConnection(); - if (!securityEnabled) { - console.debug('application security is not enabled, per api call') - session.enablePassthrough() - } + appHub.on('state', (state) => { + this.setState({ applicationState: state }); + }); + + appHub.on('options', (options) => { + this.setState({ applicationOptions: options }) + }) - if (await session.check()) { - const appHub = createApplicationHubConnection(); - - appHub.on('state', (state) => { - this.setState({ applicationState: state }); - }); + appHub.onreconnecting(() => this.setState({ error: true, retriesExhausted: false })); + appHub.onclose(() => this.setState({ error: true, retriesExhausted: true })); + appHub.onreconnected(() => this.setState({ error: false, retriesExhausted: false })); - appHub.on('options', (options) => { - this.setState({ applicationOptions: options }) - }) - - appHub.onreconnecting(() => this.setState({ error: true, retriesExhausted: false })); - appHub.onclose(() => this.setState({ error: true, retriesExhausted: true })); - appHub.onreconnected(() => this.setState({ error: false, retriesExhausted: false })); - - await appHub.start(); + await appHub.start(); + } + + this.setState({ + error: false, + }); + } catch (err) { + console.error(err) + this.setState({ error: true, retriesExhausted: true }) + } finally { + this.setState({ initialized: true }); } - - this.setState({ - error: false, - }); - } catch (err) { - console.error(err) - this.setState({ error: true, retriesExhausted: true }) - } finally { - this.setState({ initialized: true }); - } + }) } login = (username, password, rememberMe) => { this.setState({ login: { ...this.state.login, pending: true, error: undefined }}, async () => { try { await session.login({ username, password, rememberMe }); - this.setState({ login: { ...this.state.login, pending: false, error: false }}); + this.setState({ login: { ...this.state.login, pending: false, error: false }}, () => this.init()); } catch (error) { this.setState({ login: { ...this.state.login, pending: false, error }}); } |
