fix unauthenticated flow

This commit is contained in:
jeffvli
2025-11-18 17:31:40 -08:00
parent 51e33d774a
commit 34da091a8d
4 changed files with 14 additions and 24 deletions
@@ -238,6 +238,7 @@ export const AddServerForm = ({ onCancel }: AddServerFormProps) => {
context: 'name', context: 'name',
postProcess: 'titleCase', postProcess: 'titleCase',
})} })}
required
{...form.getInputProps('name')} {...form.getInputProps('name')}
/> />
<TextInput <TextInput
@@ -246,6 +247,7 @@ export const AddServerForm = ({ onCancel }: AddServerFormProps) => {
context: 'url', context: 'url',
postProcess: 'titleCase', postProcess: 'titleCase',
})} })}
required
{...form.getInputProps('url')} {...form.getInputProps('url')}
/> />
</Group> </Group>
@@ -254,6 +256,7 @@ export const AddServerForm = ({ onCancel }: AddServerFormProps) => {
context: 'username', context: 'username',
postProcess: 'titleCase', postProcess: 'titleCase',
})} })}
required
{...form.getInputProps('username')} {...form.getInputProps('username')}
/> />
<PasswordInput <PasswordInput
@@ -298,7 +301,7 @@ export const AddServerForm = ({ onCancel }: AddServerFormProps) => {
})} })}
/> />
)} )}
<Group justify="flex-end"> <Group grow>
{onCancel && ( {onCancel && (
<ModalButton onClick={onCancel}>{t('common.cancel')}</ModalButton> <ModalButton onClick={onCancel}>{t('common.cancel')}</ModalButton>
)} )}
@@ -58,6 +58,11 @@ export const useServerAuthenticated = () => {
}, 300); }, 300);
useEffect(() => { useEffect(() => {
if (!server) {
setReady(AuthState.INVALID);
return;
}
if (priorServerId.current !== server?.id) { if (priorServerId.current !== server?.id) {
const serverWithAuth = getServerById(server!.id); const serverWithAuth = getServerById(server!.id);
priorServerId.current = server?.id || ''; priorServerId.current = server?.id || '';
+1 -23
View File
@@ -1,6 +1,5 @@
import { NuqsAdapter } from '@offlegacy/nuqs-hash-router'; import { NuqsAdapter } from '@offlegacy/nuqs-hash-router';
import isElectron from 'is-electron'; import { useMemo } from 'react';
import { useEffect, useMemo } from 'react';
import { Navigate, Outlet } from 'react-router'; import { Navigate, Outlet } from 'react-router';
import { useServerAuthenticated } from '/@/renderer/hooks/use-server-authenticated'; import { useServerAuthenticated } from '/@/renderer/hooks/use-server-authenticated';
@@ -8,16 +7,10 @@ import { AppRoute } from '/@/renderer/router/routes';
import { useCurrentServer } from '/@/renderer/store'; import { useCurrentServer } from '/@/renderer/store';
import { Center } from '/@/shared/components/center/center'; import { Center } from '/@/shared/components/center/center';
import { Spinner } from '/@/shared/components/spinner/spinner'; import { Spinner } from '/@/shared/components/spinner/spinner';
import { toast } from '/@/shared/components/toast/toast';
import { AuthState } from '/@/shared/types/types'; import { AuthState } from '/@/shared/types/types';
const ipc = isElectron() ? window.api.ipc : null;
const utils = isElectron() ? window.api.utils : null;
const mpvPlayerListener = isElectron() ? window.api.mpvPlayerListener : null;
export const AppOutlet = () => { export const AppOutlet = () => {
const currentServer = useCurrentServer(); const currentServer = useCurrentServer();
// const setFallback = useSetPlayerFallback();
const authState = useServerAuthenticated(); const authState = useServerAuthenticated();
const isActionsRequired = useMemo(() => { const isActionsRequired = useMemo(() => {
@@ -29,21 +22,6 @@ export const AppOutlet = () => {
return isActionRequired; return isActionRequired;
}, [currentServer]); }, [currentServer]);
// useEffect(() => {
// utils?.mainMessageListener((_event, data) => {
// toast.show(data);
// });
// mpvPlayerListener?.rendererPlayerFallback((_event, data) => {
// setFallback(data);
// });
// return () => {
// ipc?.removeAllListeners('toast-from-main');
// ipc?.removeAllListeners('renderer-player-fallback');
// };
// }, [setFallback]);
if (authState === AuthState.LOADING) { if (authState === AuthState.LOADING) {
return ( return (
<Center h="100vh" w="100%"> <Center h="100vh" w="100%">
+4
View File
@@ -116,6 +116,10 @@ export const useCurrentServerId = () => useAuthStore((state) => state.currentSer
export const useCurrentServer = () => export const useCurrentServer = () =>
useAuthStore((state) => { useAuthStore((state) => {
if (!state.currentServer) {
return null;
}
return { return {
features: state.currentServer?.features, features: state.currentServer?.features,
id: state.currentServer?.id, id: state.currentServer?.id,