From 6626a8c41355904e59ffd2598b6bfaa761a7ea15 Mon Sep 17 00:00:00 2001 From: fathisiddiqi Date: Tue, 24 Jun 2025 20:15:13 +0700 Subject: [PATCH 1/2] fix: set redirect uri for google login and prevent router push when login by google --- .github/CONTRIBUTING.md | 1 + apps/web/.env.example | 1 + apps/web/src/app/(auth)/login/page.tsx | 2 +- packages/auth/src/server.ts | 5 +++-- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index b9e2275..120a3ce 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -87,6 +87,7 @@ Thank you for your interest in contributing to OpenCut! This document provides g # Only needed if you want to test Google login GOOGLE_CLIENT_ID="your-google-client-id" GOOGLE_CLIENT_SECRET="your-google-client-secret" + GOOGLE_REDIRECT_URI="http://localhost:3000/api/auth/callback/google" ``` 5. Run database migrations: `bun run db:migrate` diff --git a/apps/web/.env.example b/apps/web/.env.example index 0b4c649..70c48e2 100644 --- a/apps/web/.env.example +++ b/apps/web/.env.example @@ -10,6 +10,7 @@ BETTER_AUTH_SECRET=your-secret-key-here #Google Clients GOOGLE_CLIENT_ID= GOOGLE_CLIENT_SECRET= +GOOGLE_REDIRECT_URI=http://localhost:3000/api/auth/callback/google # Development Environment NODE_ENV=development diff --git a/apps/web/src/app/(auth)/login/page.tsx b/apps/web/src/app/(auth)/login/page.tsx index 73c34e1..755784f 100644 --- a/apps/web/src/app/(auth)/login/page.tsx +++ b/apps/web/src/app/(auth)/login/page.tsx @@ -52,8 +52,8 @@ function LoginForm() { try { await signIn.social({ provider: "google", + callbackURL: "/editor", }); - router.push("/editor"); } catch (error) { setError("Failed to sign in with Google. Please try again."); setIsGoogleLoading(false); diff --git a/packages/auth/src/server.ts b/packages/auth/src/server.ts index f6c68dc..7c32fbf 100644 --- a/packages/auth/src/server.ts +++ b/packages/auth/src/server.ts @@ -16,14 +16,15 @@ export const auth = betterAuth({ emailAndPassword: { enabled: true, }, - socialProviders: { + socialProviders: { google: { clientId: process.env.GOOGLE_CLIENT_ID as string, clientSecret: process.env.GOOGLE_CLIENT_SECRET as string, + redirectURI: process.env.GOOGLE_REDIRECT_URI as string, }, }, appName: "OpenCut", trustedOrigins: ["http://localhost:3000"], }); -export type Auth = typeof auth; \ No newline at end of file +export type Auth = typeof auth; From 2f5bde105158e189b396e2a6d5181ac971a4ed9f Mon Sep 17 00:00:00 2001 From: fathisiddiqi Date: Thu, 26 Jun 2025 09:55:30 +0700 Subject: [PATCH 2/2] fix: remove GOOGLE_REDIRECT_URI env due to better auth set the default of that --- .github/CONTRIBUTING.md | 1 - apps/web/.env.example | 1 - packages/auth/src/server.ts | 1 - 3 files changed, 3 deletions(-) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 120a3ce..b9e2275 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -87,7 +87,6 @@ Thank you for your interest in contributing to OpenCut! This document provides g # Only needed if you want to test Google login GOOGLE_CLIENT_ID="your-google-client-id" GOOGLE_CLIENT_SECRET="your-google-client-secret" - GOOGLE_REDIRECT_URI="http://localhost:3000/api/auth/callback/google" ``` 5. Run database migrations: `bun run db:migrate` diff --git a/apps/web/.env.example b/apps/web/.env.example index 70c48e2..0b4c649 100644 --- a/apps/web/.env.example +++ b/apps/web/.env.example @@ -10,7 +10,6 @@ BETTER_AUTH_SECRET=your-secret-key-here #Google Clients GOOGLE_CLIENT_ID= GOOGLE_CLIENT_SECRET= -GOOGLE_REDIRECT_URI=http://localhost:3000/api/auth/callback/google # Development Environment NODE_ENV=development diff --git a/packages/auth/src/server.ts b/packages/auth/src/server.ts index 7c32fbf..6590c0a 100644 --- a/packages/auth/src/server.ts +++ b/packages/auth/src/server.ts @@ -20,7 +20,6 @@ export const auth = betterAuth({ google: { clientId: process.env.GOOGLE_CLIENT_ID as string, clientSecret: process.env.GOOGLE_CLIENT_SECRET as string, - redirectURI: process.env.GOOGLE_REDIRECT_URI as string, }, }, appName: "OpenCut",