Skip to content

Commit f693cf4

Browse files
committed
Merge branch 'main' into feat/byok
2 parents 6333acc + 1ecaa10 commit f693cf4

2 files changed

Lines changed: 31 additions & 10 deletions

File tree

webapp/_webapp/src/index.css

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,12 @@ object {
219219
border: 1px solid;
220220
background-color: transparent;
221221
overflow: hidden;
222-
@apply overflow-hidden w-full h-full dark:!border-default-200 !border-default-200;
222+
@apply overflow-hidden w-full h-full dark:!border-default-200 !border-default-200 text-default-800;
223+
224+
textarea,
225+
input {
226+
background-color: var(--pd-default-bg);
227+
}
223228
}
224229

225230
.pd-app-control-title-bar {

webapp/_webapp/src/libs/apiclient.ts

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { EventEmitter } from "events";
77
import { ErrorCode, ErrorSchema } from "../pkg/gen/apiclient/shared/v1/shared_pb";
88
import { errorToast } from "./toasts";
99
import { storage } from "./storage";
10+
import { useAuthStore } from "../stores/auth-store";
1011

1112
// Exhaustive type check helper - will cause compile error if a case is not handled
1213
const assertNever = (x: never): never => {
@@ -29,6 +30,7 @@ class ApiClient {
2930
private axiosInstance: AxiosInstance;
3031
private refreshToken: string | null;
3132
private onTokenRefreshedEventEmitter: EventEmitter;
33+
private refreshPromise: Promise<void> | null = null;
3234

3335
constructor(baseURL: string, apiVersion: ApiVersion) {
3436
this.axiosInstance = axios.create({
@@ -64,6 +66,8 @@ class ApiClient {
6466
}
6567

6668
setTokens(token: string, refreshToken: string): void {
69+
useAuthStore.getState().setToken(token);
70+
useAuthStore.getState().setRefreshToken(refreshToken);
6771
this.refreshToken = refreshToken;
6872
this.axiosInstance.defaults.headers.common["Authorization"] = `Bearer ${token}`;
6973
}
@@ -89,15 +93,27 @@ class ApiClient {
8993
}
9094

9195
async refresh() {
92-
const response = await this.axiosInstance.post<JsonValue>("/auth/refresh", {
93-
refreshToken: this.refreshToken,
94-
});
95-
const resp = fromJson(RefreshTokenResponseSchema, response.data);
96-
this.setTokens(resp.token, resp.refreshToken);
97-
this.onTokenRefreshedEventEmitter.emit("tokenRefreshed", {
98-
token: resp.token,
99-
refreshToken: resp.refreshToken,
100-
});
96+
if (this.refreshPromise) {
97+
return this.refreshPromise;
98+
}
99+
100+
this.refreshPromise = (async () => {
101+
try {
102+
const response = await this.axiosInstance.post<JsonValue>("/auth/refresh", {
103+
refreshToken: this.refreshToken,
104+
});
105+
const resp = fromJson(RefreshTokenResponseSchema, response.data);
106+
this.setTokens(resp.token, resp.refreshToken);
107+
this.onTokenRefreshedEventEmitter.emit("tokenRefreshed", {
108+
token: resp.token,
109+
refreshToken: resp.refreshToken,
110+
});
111+
} finally {
112+
this.refreshPromise = null;
113+
}
114+
})();
115+
116+
return this.refreshPromise;
101117
}
102118

103119
private async requestWithRefresh(config: AxiosRequestConfig): Promise<JsonValue> {

0 commit comments

Comments
 (0)