always create a jwt when connecting to a space if a hf_token is present (#8296)

* fix param name

* format

* always create a jwt if a hf token is present

* add changeset

* add changeset

* remove throw

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
This commit is contained in:
pngwn 2024-05-15 15:20:34 +01:00 committed by GitHub
parent 4350215348
commit 929d216d49
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 20 additions and 18 deletions

View File

@ -0,0 +1,6 @@
---
"@gradio/client": patch
"gradio": patch
---
fix:always create a jwt when connecting to a space if a hf_token is present

View File

@ -136,28 +136,24 @@ export class Client {
try {
await this._resolve_config().then(async ({ config }) => {
if (config) {
this.config = config;
if (this.config && this.config.connect_heartbeat) {
if (this.config.space_id && this.options.hf_token) {
this.jwt = await get_jwt(
this.config.space_id,
this.options.hf_token
);
}
this.config = config;
// connect to the heartbeat endpoint via GET request
const heartbeat_url = new URL(
`${this.config.root}/heartbeat/${this.session_hash}`
);
if (config.space_id && this.options.hf_token) {
this.jwt = await get_jwt(config.space_id, this.options.hf_token);
}
// if the jwt is available, add it to the query params
if (this.jwt) {
heartbeat_url.searchParams.set("__sign", this.jwt);
}
if (this.config && this.config.connect_heartbeat) {
// connect to the heartbeat endpoint via GET request
const heartbeat_url = new URL(
`${this.config.root}/heartbeat/${this.session_hash}`
);
this.heartbeat_event = await this.stream(heartbeat_url); // Just connect to the endpoint without parsing the response. Ref: https://github.com/gradio-app/gradio/pull/7974#discussion_r1557717540
// if the jwt is available, add it to the query params
if (this.jwt) {
heartbeat_url.searchParams.set("__sign", this.jwt);
}
this.heartbeat_event = await this.stream(heartbeat_url); // Just connect to the endpoint without parsing the response. Ref: https://github.com/gradio-app/gradio/pull/7974#discussion_r1557717540
}
});
} catch (e) {