Skip to content

Commit

Permalink
always create a jwt when connecting to a space if a hf_token is prese…
Browse files Browse the repository at this point in the history
…nt (#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>
  • Loading branch information
pngwn and gradio-pr-bot committed May 15, 2024
1 parent 4350215 commit 929d216
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 21 deletions.
6 changes: 6 additions & 0 deletions .changeset/ready-hotels-create.md
Original file line number Diff line number Diff line change
@@ -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
38 changes: 17 additions & 21 deletions client/js/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}

// connect to the heartbeat endpoint via GET request
const heartbeat_url = new URL(
`${this.config.root}/heartbeat/${this.session_hash}`
);

// 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
this.config = config;

if (config.space_id && this.options.hf_token) {
this.jwt = await get_jwt(config.space_id, this.options.hf_token);
}

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}`
);

// 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) {
Expand Down

0 comments on commit 929d216

Please sign in to comment.