mirror of
https://github.com/antebudimir/feishin.git
synced 2026-01-02 19:01:40 +00:00
handle Navidrome login loop error
This commit is contained in:
parent
bdc372636b
commit
fb584b35a9
3 changed files with 44 additions and 23 deletions
|
|
@ -62,7 +62,8 @@ const ActionRequiredRoute = () => {
|
||||||
</Group>
|
</Group>
|
||||||
<Stack mt="2rem">
|
<Stack mt="2rem">
|
||||||
{canReturnHome && <Navigate to={AppRoute.HOME} />}
|
{canReturnHome && <Navigate to={AppRoute.HOME} />}
|
||||||
{!displayedCheck && (
|
{/* This should be displayed if a credential is required */}
|
||||||
|
{isCredentialRequired && (
|
||||||
<Group
|
<Group
|
||||||
justify="center"
|
justify="center"
|
||||||
wrap="nowrap"
|
wrap="nowrap"
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,26 @@
|
||||||
|
import isElectron from 'is-electron';
|
||||||
import { debounce } from 'lodash';
|
import { debounce } from 'lodash';
|
||||||
import { useCallback, useEffect, useRef, useState } from 'react';
|
import { useCallback, useEffect, useRef, useState } from 'react';
|
||||||
|
|
||||||
import { api } from '/@/renderer/api';
|
import { api } from '/@/renderer/api';
|
||||||
import { useCurrentServer } from '/@/renderer/store';
|
import { useAuthStoreActions, useCurrentServer } from '/@/renderer/store';
|
||||||
import { toast } from '/@/shared/components/toast/toast';
|
import { toast } from '/@/shared/components/toast/toast';
|
||||||
import { SongListSort, SortOrder } from '/@/shared/types/domain-types';
|
import { SongListSort, SortOrder } from '/@/shared/types/domain-types';
|
||||||
import { AuthState, ServerListItem, ServerType } from '/@/shared/types/types';
|
import { AuthState, ServerListItem, ServerType } from '/@/shared/types/types';
|
||||||
|
|
||||||
|
const localSettings = isElectron() ? window.api.localSettings : null;
|
||||||
|
|
||||||
export const useServerAuthenticated = () => {
|
export const useServerAuthenticated = () => {
|
||||||
const priorServerId = useRef<string | undefined>(undefined);
|
const priorServerId = useRef<string | undefined>(undefined);
|
||||||
const server = useCurrentServer();
|
const server = useCurrentServer();
|
||||||
const [ready, setReady] = useState(
|
const [ready, setReady] = useState(
|
||||||
server?.type === ServerType.NAVIDROME ? AuthState.LOADING : AuthState.VALID,
|
server?.type === ServerType.NAVIDROME ? AuthState.VALID : AuthState.VALID,
|
||||||
);
|
);
|
||||||
|
|
||||||
const authenticateNavidrome = useCallback(async (server: ServerListItem) => {
|
const { updateServer } = useAuthStoreActions();
|
||||||
|
|
||||||
|
const authenticateNavidrome = useCallback(
|
||||||
|
async (server: ServerListItem) => {
|
||||||
// This trick works because navidrome-api.ts will internally check for authentication
|
// This trick works because navidrome-api.ts will internally check for authentication
|
||||||
// failures and try to log in again (where available). So, all that's necessary is
|
// failures and try to log in again (where available). So, all that's necessary is
|
||||||
// making one request first
|
// making one request first
|
||||||
|
|
@ -31,10 +37,21 @@ export const useServerAuthenticated = () => {
|
||||||
|
|
||||||
setReady(AuthState.VALID);
|
setReady(AuthState.VALID);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
// Clear server credentials (and saved password).
|
||||||
|
if (server.savePassword && localSettings) {
|
||||||
|
localSettings.passwordRemove(server.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
server.credential = '';
|
||||||
|
updateServer(server.id, server);
|
||||||
|
|
||||||
toast.error({ message: (error as Error).message });
|
toast.error({ message: (error as Error).message });
|
||||||
|
|
||||||
setReady(AuthState.INVALID);
|
setReady(AuthState.INVALID);
|
||||||
}
|
}
|
||||||
}, []);
|
},
|
||||||
|
[updateServer],
|
||||||
|
);
|
||||||
|
|
||||||
const debouncedAuth = debounce((server: ServerListItem) => {
|
const debouncedAuth = debounce((server: ServerListItem) => {
|
||||||
authenticateNavidrome(server).catch(console.error);
|
authenticateNavidrome(server).catch(console.error);
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,8 @@ export const AppOutlet = () => {
|
||||||
const setFallback = useSetPlayerFallback();
|
const setFallback = useSetPlayerFallback();
|
||||||
const authState = useServerAuthenticated();
|
const authState = useServerAuthenticated();
|
||||||
|
|
||||||
|
console.log(authState);
|
||||||
|
|
||||||
const isActionsRequired = useMemo(() => {
|
const isActionsRequired = useMemo(() => {
|
||||||
const isServerRequired = !currentServer;
|
const isServerRequired = !currentServer;
|
||||||
|
|
||||||
|
|
@ -55,6 +57,7 @@ export const AppOutlet = () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isActionsRequired || authState === AuthState.INVALID) {
|
if (isActionsRequired || authState === AuthState.INVALID) {
|
||||||
|
console.log('required', isActionsRequired);
|
||||||
return (
|
return (
|
||||||
<Navigate
|
<Navigate
|
||||||
replace
|
replace
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue