[bugfix]: Check for Navidrome authentication on startup

Resolves #403.
This PR introduces a startup check for Navidrome that tries a simple API request (/songs) before loading homepage.
If the check fails, Navidrome API will fallback to trying saved password (if available).

Notes:
- It might also be worthwhile to do a periodic poll?
This commit is contained in:
Kendall Garner 2024-02-16 13:37:49 -08:00
parent 20b161ee86
commit b2fce071a9
No known key found for this signature in database
GPG key ID: 18D2767419676C87
3 changed files with 69 additions and 2 deletions

View file

@ -3,7 +3,9 @@ import isElectron from 'is-electron';
import { Navigate, Outlet } from 'react-router-dom';
import { AppRoute } from '/@/renderer/router/routes';
import { useCurrentServer, useSetPlayerFallback } from '/@/renderer/store';
import { toast } from '/@/renderer/components';
import { Spinner, toast } from '/@/renderer/components';
import { useServerAuthenticated } from '/@/renderer/hooks/use-server-authenticated';
import { AuthState } from '/@/renderer/types';
const ipc = isElectron() ? window.electron.ipc : null;
const utils = isElectron() ? window.electron.utils : null;
@ -12,6 +14,7 @@ const mpvPlayerListener = isElectron() ? window.electron.mpvPlayerListener : nul
export const AppOutlet = () => {
const currentServer = useCurrentServer();
const setFallback = useSetPlayerFallback();
const authState = useServerAuthenticated();
const isActionsRequired = useMemo(() => {
const isServerRequired = !currentServer;
@ -37,7 +40,11 @@ export const AppOutlet = () => {
};
}, [setFallback]);
if (isActionsRequired) {
if (authState === AuthState.LOADING) {
return <Spinner container />;
}
if (isActionsRequired || authState === AuthState.INVALID) {
return (
<Navigate
replace