feat: redirect code parameter to auth callback in middleware\n\nAdapt middleware to handle parameter and route to .
This commit is contained in:
parent
e8a65645c2
commit
7bc69a7a36
13
app/page.tsx
13
app/page.tsx
@ -1,7 +1,18 @@
|
||||
import { redirect } from "next/navigation"
|
||||
import { createClient } from "@/lib/supabase/server"
|
||||
|
||||
export default async function Page() {
|
||||
export default async function Page({
|
||||
searchParams,
|
||||
}: {
|
||||
searchParams: Promise<{ code?: string }>
|
||||
}) {
|
||||
const params = await searchParams
|
||||
|
||||
// If there's an auth code, redirect to callback to exchange it
|
||||
if (params.code) {
|
||||
redirect(`/auth/callback?code=${params.code}`)
|
||||
}
|
||||
|
||||
const supabase = await createClient()
|
||||
const {
|
||||
data: { user },
|
||||
|
||||
@ -29,6 +29,15 @@ export async function updateSession(request: NextRequest) {
|
||||
},
|
||||
)
|
||||
|
||||
// Intercept auth confirmation codes on any route and redirect to callback
|
||||
const code = request.nextUrl.searchParams.get('code')
|
||||
if (code && !request.nextUrl.pathname.startsWith('/auth/callback')) {
|
||||
const url = request.nextUrl.clone()
|
||||
url.pathname = '/auth/callback'
|
||||
url.searchParams.set('code', code)
|
||||
return NextResponse.redirect(url)
|
||||
}
|
||||
|
||||
const {
|
||||
data: { user },
|
||||
} = await supabase.auth.getUser()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user