Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/app/auth/callback/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@ import { createServerClient } from "@supabase/ssr";
import { cookies } from "next/headers";
import { NextResponse } from "next/server";

// Always redirect to the canonical domain after OAuth so that arriving via
// any auto-assigned Vercel URL (e.g. studymapp-student-suite.vercel.app)
// doesn't leave the user stranded on the wrong domain.
const SITE_URL =
process.env.NEXT_PUBLIC_SITE_URL ?? "https://studymapp.vercel.app";

export async function GET(request: Request) {
const { searchParams, origin } = new URL(request.url);
const { searchParams } = new URL(request.url);
const code = searchParams.get("code");
const next = searchParams.get("next") ?? "/";

Expand All @@ -28,9 +34,9 @@ export async function GET(request: Request) {

const { error } = await supabase.auth.exchangeCodeForSession(code);
if (!error) {
return NextResponse.redirect(`${origin}${next}`);
return NextResponse.redirect(`${SITE_URL}${next}`);
}
}

return NextResponse.redirect(`${origin}/login?error=auth_error`);
return NextResponse.redirect(`${SITE_URL}/login?error=auth_error`);
}
6 changes: 5 additions & 1 deletion src/app/login/login-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { toast } from "sonner";
import { Loader2 } from "lucide-react";

import { createClient } from "@/lib/supabase/client";
import { site } from "@/lib/site";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
Expand Down Expand Up @@ -50,7 +51,10 @@ export function LoginForm() {
}

async function handleGoogle() {
const siteUrl = process.env.NEXT_PUBLIC_SITE_URL ?? window.location.origin;
// Use the explicit env var for local dev (http://localhost:3000),
// fall back to the hardcoded canonical domain so any auto-assigned
// Vercel URL never leaks into the OAuth redirectTo.
const siteUrl = process.env.NEXT_PUBLIC_SITE_URL ?? site.url;
const { error } = await supabase.auth.signInWithOAuth({
provider: "google",
options: {
Expand Down
Loading