Skip to content

Commit 0120cd1

Browse files
committed
token change
1 parent c971df7 commit 0120cd1

File tree

2 files changed

+3
-27
lines changed

2 files changed

+3
-27
lines changed

src/lib/state/conversations.svelte.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ export class ConversationClass {
251251
// }
252252

253253
if (error.message.includes("token seems invalid")) {
254-
token.reset();
254+
token.requestTokenFromParent();
255255
}
256256

257257
if (error.name !== "AbortError") {
@@ -486,7 +486,7 @@ class Conversations {
486486
}
487487

488488
if (error.message.includes("token seems invalid")) {
489-
token.reset();
489+
token.requestTokenFromParent();
490490
}
491491

492492
if (error.name !== "AbortError") {

src/lib/state/token.svelte.ts

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,22 @@
11
import { env } from "$env/dynamic/public";
2-
import { safeParse } from "$lib/utils/json.js";
3-
import typia from "typia";
4-
5-
const key = "hf_token";
62

73
class Token {
84
#value = $state("");
9-
writeToLocalStorage = $state(true);
105

116
constructor() {
127
if (env.PUBLIC_HF_TOKEN) {
138
this.#value = env.PUBLIC_HF_TOKEN;
149
return;
1510
}
1611

17-
const storedHfToken = localStorage.getItem(key);
18-
const parsed = safeParse(storedHfToken ?? "");
19-
const storedToken = typia.is<string>(parsed) ? parsed : "";
20-
21-
if (storedToken && storedToken.startsWith("hf_jwt")) {
22-
this.#value = storedToken;
23-
} else {
24-
this.requestTokenFromParent();
25-
}
12+
this.requestTokenFromParent();
2613
}
2714

2815
get value() {
2916
return this.#value;
3017
}
3118

3219
set value(token: string) {
33-
if (this.writeToLocalStorage) {
34-
localStorage.setItem(key, JSON.stringify(token));
35-
}
3620
this.#value = token;
3721
}
3822

@@ -60,14 +44,6 @@ class Token {
6044
window.parent?.postMessage({ type: "INFERENCE_JWT_REQUEST" }, "*");
6145
});
6246
};
63-
64-
reset = () => {
65-
this.value = "";
66-
localStorage.removeItem(key);
67-
if (!env.PUBLIC_HF_TOKEN) {
68-
this.requestTokenFromParent();
69-
}
70-
};
7147
}
7248

7349
export const token = new Token();

0 commit comments

Comments
 (0)