Fix OAuth callback: remove from middleware, fix redirect URLs
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -38,6 +38,7 @@ export async function middleware(request: NextRequest) {
|
|||||||
export const config = {
|
export const config = {
|
||||||
matcher: [
|
matcher: [
|
||||||
// Only run middleware on specific routes that need auth handling
|
// Only run middleware on specific routes that need auth handling
|
||||||
|
// Note: /auth/callback is excluded - it handles its own auth flow
|
||||||
'/dashboard/:path*',
|
'/dashboard/:path*',
|
||||||
'/settings/:path*',
|
'/settings/:path*',
|
||||||
'/subscription/:path*',
|
'/subscription/:path*',
|
||||||
@@ -45,6 +46,5 @@ export const config = {
|
|||||||
'/login/',
|
'/login/',
|
||||||
'/register',
|
'/register',
|
||||||
'/register/',
|
'/register/',
|
||||||
'/auth/:path*',
|
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,19 +2,23 @@ import { createClient } from '@/lib/supabase/server'
|
|||||||
import { NextResponse } from 'next/server'
|
import { NextResponse } from 'next/server'
|
||||||
|
|
||||||
export async function GET(request: Request) {
|
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 code = searchParams.get('code')
|
||||||
const next = searchParams.get('next') ?? '/dashboard'
|
const next = searchParams.get('next') ?? '/dashboard/'
|
||||||
|
|
||||||
|
// Use the configured app URL for redirects
|
||||||
|
const baseUrl = process.env.NEXT_PUBLIC_APP_URL || 'https://lab.mlhub.it/leopost'
|
||||||
|
|
||||||
if (code) {
|
if (code) {
|
||||||
const supabase = await createClient()
|
const supabase = await createClient()
|
||||||
const { error } = await supabase.auth.exchangeCodeForSession(code)
|
const { error } = await supabase.auth.exchangeCodeForSession(code)
|
||||||
|
|
||||||
if (!error) {
|
if (!error) {
|
||||||
return NextResponse.redirect(`${origin}${next}`)
|
// Redirect to dashboard (or next page) after successful auth
|
||||||
|
return NextResponse.redirect(`${baseUrl}${next}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the user to an error page with instructions
|
// Return the user to login page with error
|
||||||
return NextResponse.redirect(`${origin}/login?error=auth_callback_error`)
|
return NextResponse.redirect(`${baseUrl}/login/?error=auth_callback_error`)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user