Skip to content

Commit 0761148

Browse files
authored
Merge pull request #9 from ZengLiangYi/phase2-electron-onboarding-spec
electron onboarding spec
2 parents 1854d28 + ad664a3 commit 0761148

33 files changed

Lines changed: 3787 additions & 235 deletions

client/src/components/AuthGate.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
api,
66
assertSafeWebAuthTransport,
77
getStoredToken,
8+
isElectronCloudHttpAuthAllowed,
89
isInsecureRemoteHttpLocation,
910
setStoredToken,
1011
} from "@/lib/api.ts";
@@ -26,7 +27,7 @@ export function AuthGate({ children }: { children: ReactNode }) {
2627
const refresh = useCallback(async () => {
2728
setError(null);
2829
setState((current) => ({ status: "loading", providerWarnings: current.providerWarnings }));
29-
if (getStoredToken() && isInsecureRemoteHttpLocation()) {
30+
if (getStoredToken() && isInsecureRemoteHttpLocation() && !isElectronCloudHttpAuthAllowed()) {
3031
setError(t("auth.insecure_http"));
3132
setState({ status: "token", providerWarnings: [] });
3233
return;
@@ -63,7 +64,7 @@ export function AuthGate({ children }: { children: ReactNode }) {
6364
setSubmitting(true);
6465
setError(null);
6566
try {
66-
if (isInsecureRemoteHttpLocation()) {
67+
if (isInsecureRemoteHttpLocation() && !isElectronCloudHttpAuthAllowed()) {
6768
setError(t("auth.insecure_http"));
6869
return;
6970
}

client/src/hooks/use-import-stream.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export function useImportStream() {
4646
}
4747

4848
fetch(`${API_BASE}/api/import/scan/stream`, {
49+
method: 'POST',
4950
headers,
5051
})
5152
.then(async (res) => {

client/src/lib/api.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,15 @@ export function isInsecureRemoteHttpLocation(location = window.location): boolea
2525
return location.protocol === "http:" && !LOCAL_HOSTS.has(location.hostname);
2626
}
2727

28+
export function isElectronCloudHttpAuthAllowed(location = window.location): boolean {
29+
const marker = window.chatcrystalElectronCloud;
30+
if (!marker?.allowInsecureHttpAuth) return false;
31+
return marker.origin === location.origin;
32+
}
33+
2834
export function assertSafeWebAuthTransport(): void {
2935
if (!isInsecureRemoteHttpLocation()) return;
36+
if (isElectronCloudHttpAuthAllowed()) return;
3037
throw new Error(
3138
"Refusing to send ChatCrystal access tokens over public HTTP. Use HTTPS or a local tunnel.",
3239
);

client/src/types/electron.d.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export {};
2+
3+
declare global {
4+
interface Window {
5+
chatcrystalElectronCloud?: {
6+
allowInsecureHttpAuth: boolean;
7+
origin: string;
8+
};
9+
}
10+
}

0 commit comments

Comments
 (0)