Fixed invalid origin, for some reason location.href is not it?
This commit is contained in:
@@ -10,6 +10,8 @@ import { python } from "@codemirror/lang-python";
|
||||
import { java } from "@codemirror/lang-java";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { LiveRun, LiveRunEvent, LiveRunMove } from "@/modules/live-run/types";
|
||||
import useAction from "@/hook/use-action";
|
||||
import { getOrigin } from "@/modules/getOrigin";
|
||||
|
||||
type Language =
|
||||
| "javascript"
|
||||
@@ -46,6 +48,7 @@ export default function Editor({
|
||||
run: LiveRun | null | undefined;
|
||||
onEvent: (s: LiveRunEvent) => void;
|
||||
}) {
|
||||
const [origin] = useAction(getOrigin);
|
||||
const [editorView, setEditorView] = useState<EditorView>();
|
||||
const scheduledTimeouts = useRef<NodeJS.Timeout[]>([]);
|
||||
const [text, setText] = useState("");
|
||||
@@ -53,9 +56,9 @@ export default function Editor({
|
||||
|
||||
// WebSocket connection
|
||||
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.send(run.id);
|
||||
@@ -97,7 +100,7 @@ export default function Editor({
|
||||
};
|
||||
|
||||
return () => ws.close();
|
||||
}, [run]);
|
||||
}, [run, ]);
|
||||
|
||||
return (
|
||||
<CodeMirror
|
||||
|
||||
@@ -6,7 +6,7 @@ import { signInWithGitHub } from "@/modules/account/actions";
|
||||
|
||||
export default function ContinueWith() {
|
||||
const continueWithGithub = () => {
|
||||
signInWithGitHub(window.location.origin);
|
||||
signInWithGitHub();
|
||||
};
|
||||
const continueWithGoogle = () => {};
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
"use server";
|
||||
|
||||
import "server-only";
|
||||
|
||||
import { createServerClient, type CookieOptions } from "@supabase/ssr";
|
||||
|
||||
@@ -2,15 +2,20 @@
|
||||
|
||||
import * as Core from "./core";
|
||||
import { createClient } from "@/lib/supabase/server";
|
||||
import { headers } from "next/headers";
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
export async function signInWithGitHub(origin: string) {
|
||||
export async function signInWithGitHub() {
|
||||
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({
|
||||
provider: "github",
|
||||
options: {
|
||||
redirectTo: `${origin}/api/auth/callback`,
|
||||
redirectTo: `${protocol}://${host}/api/auth/callback`,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -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 };
|
||||
}
|
||||
Reference in New Issue
Block a user