page.tsx / client.tsx
This commit is contained in:
38
app/(marketing)/components/auth-code-handler.tsx
Normal file
38
app/(marketing)/components/auth-code-handler.tsx
Normal file
@@ -0,0 +1,38 @@
|
||||
'use client'
|
||||
|
||||
import { useEffect } from 'react'
|
||||
import { useSearchParams, useRouter } from 'next/navigation'
|
||||
|
||||
/**
|
||||
* Auth Code Handler
|
||||
*
|
||||
* Handles auth codes that Supabase redirects to the home page
|
||||
* Redirects to /auth/callback to process the code exchange
|
||||
*/
|
||||
export function AuthCodeHandler() {
|
||||
const searchParams = useSearchParams()
|
||||
const router = useRouter()
|
||||
const code = searchParams.get('code')
|
||||
const type = searchParams.get('type')
|
||||
|
||||
useEffect(() => {
|
||||
if (code) {
|
||||
// Build callback URL with all parameters
|
||||
const callbackUrl = new URL('/auth/callback', window.location.origin)
|
||||
callbackUrl.searchParams.set('code', code)
|
||||
if (type) {
|
||||
callbackUrl.searchParams.set('type', type)
|
||||
}
|
||||
// If it's a recovery flow, ensure we redirect to update-password
|
||||
if (type === 'recovery') {
|
||||
callbackUrl.searchParams.set('next', '/update-password')
|
||||
}
|
||||
|
||||
// Redirect to callback route
|
||||
router.replace(callbackUrl.pathname + callbackUrl.search)
|
||||
}
|
||||
}, [code, type, router])
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ import type { MetadataContent } from '@/content/schemas/manifesto'
|
||||
import { HeroSectionClient } from './components/hero-section-client'
|
||||
import { BuildTimeline } from './components/build-timeline'
|
||||
import { WhyMe } from '@/components/ui/why-me'
|
||||
import { AuthCodeHandler } from './components/auth-code-handler'
|
||||
|
||||
// Generate metadata for SEO
|
||||
export async function generateMetadata(): Promise<Metadata> {
|
||||
@@ -134,6 +135,9 @@ export default async function HomePage() {
|
||||
|
||||
return (
|
||||
<>
|
||||
{/* Handle auth codes that Supabase redirects to home page */}
|
||||
<AuthCodeHandler />
|
||||
|
||||
{/* Hero Section */}
|
||||
<HeroSectionClient
|
||||
title={
|
||||
|
||||
@@ -128,9 +128,10 @@ export async function signUpWithPassword(email: string, password: string) {
|
||||
*/
|
||||
export async function resetPasswordForEmail(email: string) {
|
||||
const supabase = createClient()
|
||||
// Redirect to callback route which will handle code exchange and redirect to /update-password
|
||||
// Redirect to callback route - Supabase will automatically add type=recovery parameter
|
||||
// The callback route will detect type=recovery and redirect to /update-password
|
||||
const { error } = await supabase.auth.resetPasswordForEmail(email, {
|
||||
redirectTo: `${window.location.origin}/auth/callback?next=/update-password`
|
||||
redirectTo: `${window.location.origin}/auth/callback`
|
||||
})
|
||||
|
||||
if (error) throw error
|
||||
|
||||
Reference in New Issue
Block a user