From 97c29dafac4ece49bbf0222d979dba137c14a6f5 Mon Sep 17 00:00:00 2001 From: Bill Yang <45103519+goldflag@users.noreply.github.com> Date: Sat, 3 May 2025 16:27:46 -0700 Subject: [PATCH] Fix callbacks (#107) * Fix callbacks * fix layout * Remove callbacks * Disable redirects * fix caddy * test disable basepath * wip * test caddy fix * remove basepath * fml * pray * kms * pray * wip * Test --- Caddyfile | 9 +-------- client/src/app/layout.tsx | 3 +-- client/src/app/login/page.tsx | 1 - client/src/app/signup/page.tsx | 2 -- client/src/middleware.ts | 11 +++++++++++ server/src/index.ts | 2 ++ server/src/lib/auth.ts | 2 +- 7 files changed, 16 insertions(+), 14 deletions(-) diff --git a/Caddyfile b/Caddyfile index bc7a5f8..4141123 100644 --- a/Caddyfile +++ b/Caddyfile @@ -4,21 +4,14 @@ # Enable compression encode zstd gzip - # Proxy API requests to the backend service handle_path /api/* { reverse_proxy backend:3001 } + # Proxy all other requests to the client service handle { reverse_proxy client:3002 } - # Optional: Add security headers (example) - # header { - # Strict-Transport-Security max-age=31536000; - # X-Content-Type-Options nosniff - # X-Frame-Options DENY - # Referrer-Policy strict-origin-when-cross-origin - # } } \ No newline at end of file diff --git a/client/src/app/layout.tsx b/client/src/app/layout.tsx index e683828..efc0fe0 100644 --- a/client/src/app/layout.tsx +++ b/client/src/app/layout.tsx @@ -2,8 +2,7 @@ import { BACKEND_URL } from "@/lib/const"; import QueryProvider from "@/providers/QueryProvider"; -import type { Metadata } from "next"; -import { Inter, Manrope } from "next/font/google"; +import { Inter } from "next/font/google"; import { redirect, usePathname } from "next/navigation"; import { useEffect, useState } from "react"; import { Toaster } from "../components/ui/sonner"; diff --git a/client/src/app/login/page.tsx b/client/src/app/login/page.tsx index 5165786..e9e405b 100644 --- a/client/src/app/login/page.tsx +++ b/client/src/app/login/page.tsx @@ -54,7 +54,6 @@ export default function Page() { try { await authClient.signIn.social({ provider, - callbackURL: "/", }); } catch (error) { setError(String(error)); diff --git a/client/src/app/signup/page.tsx b/client/src/app/signup/page.tsx index 8eb6f50..71da014 100644 --- a/client/src/app/signup/page.tsx +++ b/client/src/app/signup/page.tsx @@ -255,7 +255,6 @@ export default function SignupPage() { onClick={() => { authClient.signIn.social({ provider: "google", - callbackURL: "/", }); }} className="transition-all duration-300 hover:bg-muted bg-neutral-800/50 border-neutral-700" @@ -269,7 +268,6 @@ export default function SignupPage() { onClick={() => { authClient.signIn.social({ provider: "github", - callbackURL: "/", }); }} className="transition-all duration-300 hover:bg-muted bg-neutral-800/50 border-neutral-700" diff --git a/client/src/middleware.ts b/client/src/middleware.ts index 38fcfe5..caed560 100644 --- a/client/src/middleware.ts +++ b/client/src/middleware.ts @@ -10,6 +10,17 @@ export async function middleware(request: NextRequest) { return NextResponse.next(); } + // Handle GitHub OAuth callback redirect + if (path === "/auth/callback/github" || path === "/auth/callback/google") { + const redirectUrl = new URL( + `/api${path}${request.nextUrl.search}`, + request.url + ); + const response = NextResponse.redirect(redirectUrl); + response.headers.set("Cache-Control", "no-store, max-age=0"); + return response; + } + // Check if we're on a site route without a specific page // This matches exactly /{siteId} with nothing after it const siteRoutePattern = /^\/([^/]+)$/; diff --git a/server/src/index.ts b/server/src/index.ts index 2e43a88..78ce288 100644 --- a/server/src/index.ts +++ b/server/src/index.ts @@ -121,6 +121,8 @@ const PUBLIC_ROUTES: string[] = [ "/script", "/auth", "/api/auth", + "/api/auth/callback/google", + "/api/auth/callback/github", "/api/stripe/webhook", // Add webhook to public routes ]; diff --git a/server/src/lib/auth.ts b/server/src/lib/auth.ts index 8ebf81f..add3bbf 100644 --- a/server/src/lib/auth.ts +++ b/server/src/lib/auth.ts @@ -6,7 +6,7 @@ import { eq } from "drizzle-orm"; import pg from "pg"; import { db } from "../db/postgres/postgres.js"; import * as schema from "../db/postgres/schema.js"; -import { DISABLE_SIGNUP } from "./const.js"; +import { DISABLE_SIGNUP, IS_CLOUD } from "./const.js"; dotenv.config();