落地页登录态感知:已登录用户隐藏登录/注册按钮
InstitutionalLandingPage 挂载时检测 Supabase session, 用户已登录则仅显示"进入产品"直达 /terminal,未登录则保留完整按钮组。 Tested: npm run build 通过
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
|
import { useEffect, useState } from "react";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import {
|
import {
|
||||||
Activity,
|
Activity,
|
||||||
@@ -16,6 +17,10 @@ import {
|
|||||||
TrendingUp,
|
TrendingUp,
|
||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
import { I18nProvider, useI18n } from "@/hooks/useI18n";
|
import { I18nProvider, useI18n } from "@/hooks/useI18n";
|
||||||
|
import {
|
||||||
|
getSupabaseBrowserClient,
|
||||||
|
hasSupabasePublicEnv,
|
||||||
|
} from "@/lib/supabase/client";
|
||||||
|
|
||||||
const RAW_MARKET_ROWS_EN = [
|
const RAW_MARKET_ROWS_EN = [
|
||||||
["New York", "91.8°F", "+2.4", "High", "Long Yes"],
|
["New York", "91.8°F", "+2.4", "High", "Long Yes"],
|
||||||
@@ -74,6 +79,20 @@ const PRO_FEATURES_ZH = [
|
|||||||
function InstitutionalLandingScreen() {
|
function InstitutionalLandingScreen() {
|
||||||
const { locale, toggleLocale } = useI18n();
|
const { locale, toggleLocale } = useI18n();
|
||||||
const isEn = locale === "en-US";
|
const isEn = locale === "en-US";
|
||||||
|
const [isAuthenticated, setIsAuthenticated] = useState(false);
|
||||||
|
const [authChecked, setAuthChecked] = useState(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!hasSupabasePublicEnv()) {
|
||||||
|
setAuthChecked(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const supabase = getSupabaseBrowserClient();
|
||||||
|
supabase.auth.getSession().then(({ data: { session } }) => {
|
||||||
|
setIsAuthenticated(!!session?.user);
|
||||||
|
setAuthChecked(true);
|
||||||
|
});
|
||||||
|
}, []);
|
||||||
|
|
||||||
const marketRows = isEn ? RAW_MARKET_ROWS_EN : RAW_MARKET_ROWS_ZH;
|
const marketRows = isEn ? RAW_MARKET_ROWS_EN : RAW_MARKET_ROWS_ZH;
|
||||||
const coverage = isEn ? COVERAGE_EN : COVERAGE_ZH;
|
const coverage = isEn ? COVERAGE_EN : COVERAGE_ZH;
|
||||||
@@ -144,25 +163,37 @@ function InstitutionalLandingScreen() {
|
|||||||
<span className={`px-2 py-1 rounded-md transition-colors ${!isEn ? "bg-blue-50 text-blue-700 font-bold" : "hover:text-slate-800"}`}>中文</span>
|
<span className={`px-2 py-1 rounded-md transition-colors ${!isEn ? "bg-blue-50 text-blue-700 font-bold" : "hover:text-slate-800"}`}>中文</span>
|
||||||
<span className={`px-2 py-1 rounded-md transition-colors ${isEn ? "bg-blue-50 text-blue-700 font-bold" : "hover:text-slate-800"}`}>EN</span>
|
<span className={`px-2 py-1 rounded-md transition-colors ${isEn ? "bg-blue-50 text-blue-700 font-bold" : "hover:text-slate-800"}`}>EN</span>
|
||||||
</button>
|
</button>
|
||||||
<Link
|
{authChecked && isAuthenticated ? (
|
||||||
href="/auth/login?next=%2Fterminal"
|
<Link
|
||||||
className="hidden rounded-lg border border-slate-300 bg-white px-3 py-2 text-sm font-semibold text-slate-700 shadow-sm transition hover:border-slate-400 hover:text-slate-950 sm:inline-flex"
|
href="/terminal"
|
||||||
>
|
className="inline-flex items-center gap-2 rounded-lg border border-blue-700 bg-blue-600 px-3 py-2 text-sm font-bold text-white shadow-sm transition hover:bg-blue-700"
|
||||||
{isEn ? "Log in" : "登录"}
|
>
|
||||||
</Link>
|
{isEn ? "Enter Product" : "进入产品"}
|
||||||
<Link
|
<ArrowRight size={15} />
|
||||||
href="/auth/login?next=%2Fterminal&mode=signup"
|
</Link>
|
||||||
className="hidden rounded-lg bg-slate-950 px-3 py-2 text-sm font-semibold text-white shadow-sm transition hover:bg-slate-800 sm:inline-flex"
|
) : (
|
||||||
>
|
<>
|
||||||
{isEn ? "Sign Up" : "注册"}
|
<Link
|
||||||
</Link>
|
href="/auth/login?next=%2Fterminal"
|
||||||
<Link
|
className="hidden rounded-lg border border-slate-300 bg-white px-3 py-2 text-sm font-semibold text-slate-700 shadow-sm transition hover:border-slate-400 hover:text-slate-950 sm:inline-flex"
|
||||||
href="/auth/login?next=%2Fterminal"
|
>
|
||||||
className="inline-flex items-center gap-2 rounded-lg border border-blue-700 bg-blue-600 px-3 py-2 text-sm font-bold text-white shadow-sm transition hover:bg-blue-700"
|
{isEn ? "Log in" : "登录"}
|
||||||
>
|
</Link>
|
||||||
{isEn ? "Enter Product" : "进入产品"}
|
<Link
|
||||||
<ArrowRight size={15} />
|
href="/auth/login?next=%2Fterminal&mode=signup"
|
||||||
</Link>
|
className="hidden rounded-lg bg-slate-950 px-3 py-2 text-sm font-semibold text-white shadow-sm transition hover:bg-slate-800 sm:inline-flex"
|
||||||
|
>
|
||||||
|
{isEn ? "Sign Up" : "注册"}
|
||||||
|
</Link>
|
||||||
|
<Link
|
||||||
|
href="/auth/login?next=%2Fterminal"
|
||||||
|
className="inline-flex items-center gap-2 rounded-lg border border-blue-700 bg-blue-600 px-3 py-2 text-sm font-bold text-white shadow-sm transition hover:bg-blue-700"
|
||||||
|
>
|
||||||
|
{isEn ? "Enter Product" : "进入产品"}
|
||||||
|
<ArrowRight size={15} />
|
||||||
|
</Link>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
|
|||||||
Reference in New Issue
Block a user