Fix: Use OAuth authorize flow, show login prompt instead of auto-redirect
This commit is contained in:
42
app/page.tsx
42
app/page.tsx
@@ -1,29 +1,47 @@
|
||||
'use client'
|
||||
|
||||
import { useEffect } from 'react'
|
||||
import { useRouter } from 'next/navigation'
|
||||
import { useAuth } from '@/lib/auth/context'
|
||||
import { listSites } from '@/lib/api/sites'
|
||||
import type { Site } from '@/lib/api/sites'
|
||||
import { initiateOAuthFlow } from '@/lib/api/oauth'
|
||||
import LoadingOverlay from '@/components/LoadingOverlay'
|
||||
import SiteList from '@/components/sites/SiteList'
|
||||
|
||||
export default function HomePage() {
|
||||
const { user, loading } = useAuth()
|
||||
const router = useRouter()
|
||||
|
||||
useEffect(() => {
|
||||
if (!loading && !user) {
|
||||
router.push('/login')
|
||||
}
|
||||
}, [user, loading, router])
|
||||
|
||||
if (loading) {
|
||||
return <LoadingOverlay logoSrc="/ciphera_icon_no_margins.png" title="Ciphera Analytics" />
|
||||
}
|
||||
|
||||
if (!user) {
|
||||
return null
|
||||
return (
|
||||
<div className="container mx-auto px-4 py-8">
|
||||
<div className="max-w-2xl mx-auto text-center py-16">
|
||||
<h1 className="text-4xl font-bold text-neutral-900 dark:text-white mb-4">
|
||||
Welcome to Ciphera Analytics
|
||||
</h1>
|
||||
<p className="text-lg text-neutral-600 dark:text-neutral-400 mb-8">
|
||||
Privacy-first web analytics. No cookies, no tracking. GDPR compliant.
|
||||
</p>
|
||||
<div className="flex gap-4 justify-center">
|
||||
<button
|
||||
onClick={() => initiateOAuthFlow()}
|
||||
className="btn-primary"
|
||||
>
|
||||
Sign In
|
||||
</button>
|
||||
<button
|
||||
onClick={() => {
|
||||
const authUrl = process.env.NEXT_PUBLIC_AUTH_URL || 'https://auth.ciphera.net'
|
||||
window.location.href = `${authUrl}/signup?client_id=analytics-app&redirect_uri=${encodeURIComponent((process.env.NEXT_PUBLIC_APP_URL || window.location.origin) + '/auth/callback')}&response_type=code`
|
||||
}}
|
||||
className="btn-secondary"
|
||||
>
|
||||
Sign Up
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user