mirror of
https://github.com/tapframe/NuvioStreaming.git
synced 2026-03-11 17:45:38 +00:00
refactor: improve IntroDB API key verification and handle unmounted state
This commit is contained in:
parent
f8bac1aa56
commit
682d3f2eb3
2 changed files with 16 additions and 0 deletions
|
|
@ -82,6 +82,15 @@ export const PlaybackSettingsContent: React.FC<PlaybackSettingsContentProps> = (
|
|||
const [apiKeyInput, setApiKeyInput] = useState(settings?.introDbApiKey || '');
|
||||
const [isVerifyingKey, setIsVerifyingKey] = useState(false);
|
||||
|
||||
const isMounted = useRef(true);
|
||||
|
||||
useEffect(() => {
|
||||
isMounted.current = true;
|
||||
return () => {
|
||||
isMounted.current = false;
|
||||
};
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
setApiKeyInput(settings?.introDbApiKey || '');
|
||||
}, [settings?.introDbApiKey]);
|
||||
|
|
@ -95,6 +104,8 @@ export const PlaybackSettingsContent: React.FC<PlaybackSettingsContentProps> = (
|
|||
|
||||
setIsVerifyingKey(true);
|
||||
const isValid = await introService.verifyApiKey(apiKeyInput);
|
||||
|
||||
if (!isMounted.current) return;
|
||||
setIsVerifyingKey(false);
|
||||
|
||||
if (isValid) {
|
||||
|
|
|
|||
|
|
@ -209,6 +209,11 @@ export async function verifyApiKey(apiKey: string): Promise<boolean> {
|
|||
// 200/201 would also mean valid (though unexpected with empty body)
|
||||
if (response.status === 200 || response.status === 201) return true;
|
||||
|
||||
// Explicitly handle auth failures
|
||||
if (response.status === 401 || response.status === 403) return false;
|
||||
|
||||
// Log warning for unexpected states (500, 429, etc.) but fail safe
|
||||
logger.warn(`[IntroService] Verification received unexpected status: ${response.status}`);
|
||||
return false;
|
||||
} catch (error: any) {
|
||||
logger.log('[IntroService] API Key verification failed:', error.message);
|
||||
|
|
|
|||
Loading…
Reference in a new issue