fix: do a request when generating credentials to ensure the access token is valid

This commit is contained in:
Lei Nelissen
2023-06-19 23:26:38 +02:00
parent 8209db3a4b
commit 440d789f5e

View File

@@ -28,7 +28,7 @@ class CredentialGenerator extends Component<Props> {
`);
}, 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<Props> {
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,