Fixed invalid origin, for some reason location.href is not it?

This commit is contained in:
2026-02-09 20:15:50 +01:00
parent 0af907c1d4
commit 4727d796a3
5 changed files with 27 additions and 6 deletions
+6 -3
View File
@@ -10,6 +10,8 @@ import { python } from "@codemirror/lang-python";
import { java } from "@codemirror/lang-java"; import { java } from "@codemirror/lang-java";
import { useEffect, useRef, useState } from "react"; import { useEffect, useRef, useState } from "react";
import { LiveRun, LiveRunEvent, LiveRunMove } from "@/modules/live-run/types"; import { LiveRun, LiveRunEvent, LiveRunMove } from "@/modules/live-run/types";
import useAction from "@/hook/use-action";
import { getOrigin } from "@/modules/getOrigin";
type Language = type Language =
| "javascript" | "javascript"
@@ -46,6 +48,7 @@ export default function Editor({
run: LiveRun | null | undefined; run: LiveRun | null | undefined;
onEvent: (s: LiveRunEvent) => void; onEvent: (s: LiveRunEvent) => void;
}) { }) {
const [origin] = useAction(getOrigin);
const [editorView, setEditorView] = useState<EditorView>(); const [editorView, setEditorView] = useState<EditorView>();
const scheduledTimeouts = useRef<NodeJS.Timeout[]>([]); const scheduledTimeouts = useRef<NodeJS.Timeout[]>([]);
const [text, setText] = useState(""); const [text, setText] = useState("");
@@ -53,9 +56,9 @@ export default function Editor({
// WebSocket connection // WebSocket connection
useEffect(() => { useEffect(() => {
if (!run) return; if (!run || !origin?.host) return;
const ws = new WebSocket(`ws://${window.location.host}/api/view-run`); const ws = new WebSocket(`ws://${origin.host}/api/view-run`);
ws.onopen = () => { ws.onopen = () => {
ws.send(run.id); ws.send(run.id);
@@ -97,7 +100,7 @@ export default function Editor({
}; };
return () => ws.close(); return () => ws.close();
}, [run]); }, [run, ]);
return ( return (
<CodeMirror <CodeMirror
+1 -1
View File
@@ -6,7 +6,7 @@ import { signInWithGitHub } from "@/modules/account/actions";
export default function ContinueWith() { export default function ContinueWith() {
const continueWithGithub = () => { const continueWithGithub = () => {
signInWithGitHub(window.location.origin); signInWithGitHub();
}; };
const continueWithGoogle = () => {}; const continueWithGoogle = () => {};
+2
View File
@@ -1,3 +1,5 @@
"use server";
import "server-only"; import "server-only";
import { createServerClient, type CookieOptions } from "@supabase/ssr"; import { createServerClient, type CookieOptions } from "@supabase/ssr";
+7 -2
View File
@@ -2,15 +2,20 @@
import * as Core from "./core"; import * as Core from "./core";
import { createClient } from "@/lib/supabase/server"; import { createClient } from "@/lib/supabase/server";
import { headers } from "next/headers";
import { redirect } from "next/navigation"; import { redirect } from "next/navigation";
export async function signInWithGitHub(origin: string) { export async function signInWithGitHub() {
const supabase = await createClient(); const supabase = await createClient();
const h = await headers();
const host = h.get("host");
const protocol = h.get("x-forwarded-proto") ?? "https";
const { data, error } = await supabase.auth.signInWithOAuth({ const { data, error } = await supabase.auth.signInWithOAuth({
provider: "github", provider: "github",
options: { options: {
redirectTo: `${origin}/api/auth/callback`, redirectTo: `${protocol}://${host}/api/auth/callback`,
}, },
}); });
+11
View File
@@ -0,0 +1,11 @@
"use server";
import { headers } from "next/headers";
export async function getOrigin(): Promise<{ protocol: string; host: string }> {
const h = await headers();
const host = h.get("host") || "localhost:3000";
const protocol = h.get("x-forwarded-proto") ?? "https";
return { protocol, host };
}