From 440d789f5e66f6fbe3fd56febaa353a2e712c24a Mon Sep 17 00:00:00 2001 From: Lei Nelissen Date: Mon, 19 Jun 2023 23:26:38 +0200 Subject: [PATCH] fix: do a request when generating credentials to ensure the access token is valid --- .../components/CredentialGenerator.tsx | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/screens/modals/SetJellyfinServer/components/CredentialGenerator.tsx b/src/screens/modals/SetJellyfinServer/components/CredentialGenerator.tsx index cb04da5..daa6618 100644 --- a/src/screens/modals/SetJellyfinServer/components/CredentialGenerator.tsx +++ b/src/screens/modals/SetJellyfinServer/components/CredentialGenerator.tsx @@ -28,7 +28,7 @@ class CredentialGenerator extends Component { `); }, 500); - handleMessage = (event: WebViewMessageEvent) => { + handleMessage = async (event: WebViewMessageEvent) => { // GUARD: Something must be returned for this thing to work if (!event.nativeEvent.data) { return; @@ -44,8 +44,22 @@ class CredentialGenerator extends Component { return; } - // If a message is received, the credentials should be there const { credentials: { Servers: [ credentials ] }, deviceId } = data; + + // Attempt to perform a request using the credentials to see if they're + // good + const response = await fetch(`${credentials.ManualAddress}/Users/Me`, { + headers: { + 'X-Emby-Authorization': `MediaBrowser Client="", Device="", DeviceId="", Version="", Token="${credentials.AccessToken}"` + } + }); + + // GUARD: The request must succeed + if (response.status !== 200) { + return; + } + + // If a message is received, the credentials should be there this.props.onCredentialsRetrieved({ uri: credentials.ManualAddress, user_id: credentials.UserId,