Skip to content

Commit d405805

Browse files
fix: OAuth url redirect
1 parent 3304af6 commit d405805

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/lib/supabase/handle-oauth-login.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,24 @@
22

33
import { redirect } from "next/navigation";
44
import { createClient } from "./server";
5-
import { headers } from "next/headers";
5+
6+
// 1. Create a helper to get the REAL base URL
7+
const getURL = () => {
8+
let url = process.env.NEXT_PUBLIC_SITE_URL ?? process.env.VERCEL_URL ?? "http://localhost:3000";
9+
10+
url = url.includes("http") ? url : `https://${url}`;
11+
url = url.replace(/\/$/, "");
12+
return url;
13+
};
14+
615
export default async function handleOAuthLogin(provider: "github" | "google") {
716
const supabase = await createClient();
8-
const headersList = await headers();
9-
const origin = headersList.get("origin") ?? `https://${headersList.get("host")}`;;
17+
const origin = getURL();
1018
const { error, data } = await supabase.auth.signInWithOAuth({
1119
provider: provider,
12-
options: { redirectTo: `${origin}/auth/callback?next=/dashboard` },
20+
options: {
21+
redirectTo: `${origin}/auth/callback?next=/dashboard`,
22+
},
1323
});
1424

1525
if (error) throw error;

0 commit comments

Comments
 (0)