diff --git a/app/api/auth/google/callback/route.ts b/app/api/auth/google/callback/route.ts
index 00b49e8..f07125e 100644
--- a/app/api/auth/google/callback/route.ts
+++ b/app/api/auth/google/callback/route.ts
@@ -18,10 +18,17 @@ export async function GET(request: NextRequest) {
const error = searchParams.get('error');
const state = searchParams.get('state');
+ console.log('Google OAuth callback received', {
+ hasCode: !!code,
+ error: error || 'none',
+ hasState: !!state,
+ url: request.url
+ });
+
// Handle errors from Google
if (error) {
console.error('Google OAuth error:', error);
- return NextResponse.redirect(new URL('/login?error=google_oauth', request.url));
+ return NextResponse.redirect(new URL(`/login?error=${encodeURIComponent(error)}`, request.url));
}
if (!code) {
@@ -34,6 +41,8 @@ export async function GET(request: NextRequest) {
// We'll add the state to the redirect URL so the client can validate it
try {
+ console.log('Processing OAuth callback with code', code.substring(0, 5) + '...');
+
// In a real app, you would exchange the code for tokens
// and validate the tokens here
@@ -61,9 +70,11 @@ export async function GET(request: NextRequest) {
redirectUrl.searchParams.set('state', state);
}
+ console.log('Redirecting to:', redirectUrl.toString());
return NextResponse.redirect(redirectUrl);
} catch (error) {
console.error('Failed to process Google authentication:', error);
- return NextResponse.redirect(new URL('/login?error=auth_failed', request.url));
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error';
+ return NextResponse.redirect(new URL(`/login?error=auth_failed&details=${encodeURIComponent(errorMessage)}`, request.url));
}
}
\ No newline at end of file
diff --git a/app/layout.tsx b/app/layout.tsx
index 0b97c6c..e8c77e4 100644
--- a/app/layout.tsx
+++ b/app/layout.tsx
@@ -3,9 +3,16 @@ import type { Metadata } from 'next';
import { Inter } from 'next/font/google';
import { ThemeProvider } from '@/components/theme-provider';
import { Toaster } from '@/components/ui/sonner';
+import dynamic from 'next/dynamic';
const inter = Inter({ subsets: ['latin'] });
+// Import the OAuthCallbackHandler dynamically to ensure it only runs on the client
+const OAuthCallbackHandler = dynamic(
+ () => import('@/components/ui/oauth-callback-handler').then(mod => mod.OAuthCallbackHandler),
+ { ssr: false }
+);
+
export const metadata: Metadata = {
title: 'AI Movie Flow - Create Amazing Videos with AI',
description: 'Professional AI-powered video creation platform with advanced editing tools',
@@ -27,6 +34,7 @@ export default function RootLayout({
>
{children}
+