From ca924fd6ac8e1bca39f2d5e09e5689bd93f5f77c Mon Sep 17 00:00:00 2001 From: ashish Date: Mon, 21 Sep 2026 12:58:58 +0545 Subject: [PATCH] fix(auth): show sign-in only when signed out --- .../modules/common/session-menu.tsx | 25 +++++- .../modules/common/sign-in-panel.tsx | 9 ++- .../components/modules/common/site-header.tsx | 1 + .../modules/landing/hero-section.tsx | 7 +- .../modules/landing/hero-sign-in.tsx | 48 ++++++++++- apps/api/src/hooks/use-actor.ts | 4 +- apps/api/src/lib/i18n.ts | 2 + apps/api/tests/unit/hero-sign-in.test.tsx | 80 +++++++++++++++++++ apps/api/vitest.config.mts | 2 +- 9 files changed, 168 insertions(+), 10 deletions(-) create mode 100644 apps/api/tests/unit/hero-sign-in.test.tsx diff --git a/apps/api/src/components/modules/common/session-menu.tsx b/apps/api/src/components/modules/common/session-menu.tsx index 24b0595..50928d7 100644 --- a/apps/api/src/components/modules/common/session-menu.tsx +++ b/apps/api/src/components/modules/common/session-menu.tsx @@ -4,6 +4,7 @@ import type { Profile } from "@gov-portal/api-client"; import { GithubLogoIcon, ShieldCheckIcon, SignOutIcon, UserIcon } from "@phosphor-icons/react"; import Link from "next/link"; import { useState } from "react"; +import { toast } from "sonner"; import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"; import { Badge } from "@/components/ui/badge"; @@ -40,6 +41,7 @@ export function SessionMenu({ greetingLabel, profileLabel, adminLabel, + retryLabel, }: { locale: Locale; signInLabel: string; @@ -48,17 +50,36 @@ export function SessionMenu({ greetingLabel: string; profileLabel: string; adminLabel: string; + retryLabel: string; }) { - const { actor, isLoading } = useActor(); + const { actor, isLoading, isSignedOut, error, refresh } = useActor(); const [busy, setBusy] = useState(false); if (isLoading) { return null; } + if (error !== undefined || (actor === null && !isSignedOut)) { + return ( + + ); + } + if (actor === null) { return ( - diff --git a/apps/api/src/components/modules/common/sign-in-panel.tsx b/apps/api/src/components/modules/common/sign-in-panel.tsx index 7ccd5de..e14667d 100644 --- a/apps/api/src/components/modules/common/sign-in-panel.tsx +++ b/apps/api/src/components/modules/common/sign-in-panel.tsx @@ -1,6 +1,7 @@ "use client"; import { useState } from "react"; +import { toast } from "sonner"; import { Button } from "@/components/ui/button"; import { signInWithGitHub } from "@/lib/auth-client"; @@ -17,7 +18,13 @@ export function SignInPanel({ label, locale }: { label: string; locale: Locale } disabled={busy} onClick={() => { setBusy(true); - signInWithGitHub(`/${locale}/welcome`).catch(() => setBusy(false)); + signInWithGitHub(`/${locale}/welcome`).catch((error: unknown) => { + console.error("Failed to start GitHub sign-in", error); + toast.error( + error instanceof Error ? error.message : "Could not start GitHub sign-in", + ); + setBusy(false); + }); }} > {label} diff --git a/apps/api/src/components/modules/common/site-header.tsx b/apps/api/src/components/modules/common/site-header.tsx index b2f2de1..005b9c6 100644 --- a/apps/api/src/components/modules/common/site-header.tsx +++ b/apps/api/src/components/modules/common/site-header.tsx @@ -81,6 +81,7 @@ export function SiteHeader({ locale }: { locale: Locale }) { greetingLabel={dict.session.greeting} profileLabel={dict.nav.myProfile} adminLabel={dict.nav.admin} + retryLabel={dict.session.retryAccount} /> diff --git a/apps/api/src/components/modules/landing/hero-section.tsx b/apps/api/src/components/modules/landing/hero-section.tsx index 3e08e31..434e520 100644 --- a/apps/api/src/components/modules/landing/hero-section.tsx +++ b/apps/api/src/components/modules/landing/hero-section.tsx @@ -21,7 +21,12 @@ export function HeroSection({ dict, locale }: { dict: Dictionary; locale: Locale

{dict.home.lead}

- + + ); + } + + if (actor !== null) { + return ( + + ); + } + return (