@livedesk/hub 0.1.45 → 0.1.46
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/server.js +19 -11
package/package.json
CHANGED
package/src/server.js
CHANGED
|
@@ -513,11 +513,19 @@ async function getRuntimeAccessToken() {
|
|
|
513
513
|
const accessToken = String(runtimeAccessToken || '').trim();
|
|
514
514
|
const expiresSoon = runtimeAccessTokenExpiresAt > 0
|
|
515
515
|
&& runtimeAccessTokenExpiresAt <= Date.now() + HUB_ACCESS_TOKEN_REFRESH_SKEW_MS;
|
|
516
|
-
if (accessToken && !expiresSoon) {
|
|
517
|
-
return accessToken;
|
|
518
|
-
}
|
|
519
|
-
|
|
520
|
-
|
|
516
|
+
if (accessToken && !expiresSoon) {
|
|
517
|
+
return accessToken;
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
// The packaged Electron main process owns the encrypted refresh token and
|
|
521
|
+
// proactively sends each rotation to this child runtime. A second refresh
|
|
522
|
+
// owner here could consume the one-time token first and make the desktop
|
|
523
|
+
// shell appear signed out after sleep.
|
|
524
|
+
if (desktopMainAuthConfig) {
|
|
525
|
+
return accessToken;
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
const refreshToken = String(runtimeRefreshToken || '').trim();
|
|
521
529
|
if (!refreshToken) {
|
|
522
530
|
return accessToken;
|
|
523
531
|
}
|
|
@@ -621,9 +629,9 @@ async function queryAuthoritativeRuntimeRole() {
|
|
|
621
629
|
},
|
|
622
630
|
SUPABASE_AUTH_TIMEOUT_MS
|
|
623
631
|
);
|
|
624
|
-
if (response.status === 401 || response.status === 403) {
|
|
625
|
-
clearRuntimeSession();
|
|
626
|
-
throw new Error(`hub-role-query-not-authenticated:${response.status}`);
|
|
632
|
+
if (response.status === 401 || response.status === 403) {
|
|
633
|
+
if (!desktopMainAuthConfig) clearRuntimeSession();
|
|
634
|
+
throw new Error(`hub-role-query-not-authenticated:${response.status}`);
|
|
627
635
|
}
|
|
628
636
|
if (!response.ok) {
|
|
629
637
|
throw new Error(`hub-role-query-failed:${response.status}`);
|
|
@@ -4601,9 +4609,9 @@ async function callHubSupabaseRpc(name, payload, accessToken) {
|
|
|
4601
4609
|
);
|
|
4602
4610
|
const data = await response.json().catch(() => null);
|
|
4603
4611
|
const result = Array.isArray(data) ? data[0] : data;
|
|
4604
|
-
if (response.status === 401 || response.status === 403) {
|
|
4605
|
-
clearRuntimeSession();
|
|
4606
|
-
throw new Error(`${name}-not-authenticated:${response.status}`);
|
|
4612
|
+
if (response.status === 401 || response.status === 403) {
|
|
4613
|
+
if (!desktopMainAuthConfig) clearRuntimeSession();
|
|
4614
|
+
throw new Error(`${name}-not-authenticated:${response.status}`);
|
|
4607
4615
|
}
|
|
4608
4616
|
if (!response.ok) {
|
|
4609
4617
|
throw new Error(`${name}-failed:${response.status}`);
|