Skip to content

Commit

Permalink
fix: do a request when generating credentials to ensure the access to…
Browse files Browse the repository at this point in the history
…ken is valid
  • Loading branch information
leinelissen committed Jun 19, 2023
1 parent 8209db3 commit 440d789
Showing 1 changed file with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down

0 comments on commit 440d789

Please sign in to comment.