-
Notifications
You must be signed in to change notification settings - Fork 1
feat: header auth state — signed-in indicator, Open app + Log out (Privy) #43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sweetmantech
wants to merge
1
commit into
main
Choose a base branch
from
feat/header-auth-state
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| "use client"; | ||
|
|
||
| import { useRef, useState } from "react"; | ||
| import { siteConfig } from "@/lib/config"; | ||
| import { accountInitial } from "@/lib/format/accountInitial"; | ||
| import { useClickOutside } from "@/hooks/useClickOutside"; | ||
|
|
||
| type HeaderAccountMenuProps = { | ||
| email: string | undefined; | ||
| onLogout: () => Promise<void>; | ||
| }; | ||
|
|
||
| /** | ||
| * The signed-in header control: an avatar with the account's initial that | ||
| * opens a small menu — the session email, "Open app" into chat, and log out. | ||
| * Gives the marketing surface the logout it never had (chat#1850). | ||
| */ | ||
| export function HeaderAccountMenu({ email, onLogout }: HeaderAccountMenuProps) { | ||
| const [open, setOpen] = useState(false); | ||
| const menuRef = useRef<HTMLDivElement>(null); | ||
| useClickOutside(menuRef, () => setOpen(false)); | ||
|
|
||
| return ( | ||
| <div ref={menuRef} className="relative"> | ||
| <button | ||
| onClick={() => setOpen(o => !o)} | ||
| aria-label="Account menu" | ||
| aria-haspopup="menu" | ||
| aria-expanded={open} | ||
| className="flex h-8 w-8 items-center justify-center rounded-full bg-(--foreground) text-[13px] font-ui font-semibold text-(--background) transition-opacity hover:opacity-90" | ||
| > | ||
| {accountInitial(email)} | ||
| </button> | ||
| {open && ( | ||
| <div | ||
| role="menu" | ||
| className="absolute right-0 top-full mt-2 w-56 rounded-xl bg-(--background) py-1.5" | ||
| style={{ | ||
| boxShadow: | ||
| "0px 0px 0px 1px var(--border), 0px 4px 8px rgba(0,0,0,0.06), 0px 8px 16px -4px rgba(0,0,0,0.04)", | ||
| }} | ||
| > | ||
| {email && ( | ||
| <p className="truncate px-3.5 pb-1.5 pt-1 text-[12px] text-(--foreground)/50"> | ||
| {email} | ||
| </p> | ||
| )} | ||
| <a | ||
| href={siteConfig.appUrl} | ||
| role="menuitem" | ||
| className="block px-3.5 py-2 text-[13px] font-ui font-medium text-(--foreground) transition-colors hover:bg-(--foreground)/5" | ||
| > | ||
| Open app | ||
| </a> | ||
| <button | ||
| role="menuitem" | ||
| onClick={() => { | ||
| setOpen(false); | ||
| void onLogout(); | ||
| }} | ||
| className="block w-full px-3.5 py-2 text-left text-[13px] font-ui font-medium text-(--foreground)/70 transition-colors hover:bg-(--foreground)/5" | ||
| > | ||
| Log out | ||
| </button> | ||
| </div> | ||
| )} | ||
| </div> | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| "use client"; | ||
|
|
||
| import Link from "next/link"; | ||
| import { usePrivy } from "@privy-io/react-auth"; | ||
| import { siteConfig } from "@/lib/config"; | ||
| import { HeaderAccountMenu } from "@/components/layout/HeaderAccountMenu"; | ||
|
|
||
| /** | ||
| * The header's auth cluster. Signed out (and while Privy initializes) it | ||
| * renders the Sign In / Sign Up pair; once a Privy session exists it flips to | ||
| * the account menu, so the header stops pretending the visitor is anonymous | ||
| * after they authenticated through the valuation flow (chat#1850). | ||
| */ | ||
| export function HeaderAuth() { | ||
| const { ready, authenticated, user, logout } = usePrivy(); | ||
|
|
||
| if (ready && authenticated) { | ||
| return ( | ||
| <HeaderAccountMenu email={user?.email?.address} onLogout={logout} /> | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| <> | ||
| <Link | ||
| href={siteConfig.appUrl} | ||
| className="hidden sm:inline-block text-[14px] font-ui font-medium text-(--foreground)/70 hover:text-(--foreground) transition-colors px-4 py-1.5 rounded-full border border-(--border) hover:border-(--foreground)/20" | ||
| > | ||
| Sign In | ||
| </Link> | ||
| <Link | ||
| href={siteConfig.appUrl} | ||
| className="bg-(--foreground) text-(--background) px-5 py-2 rounded-full text-[14px] font-ui font-semibold hover:opacity-90 transition-opacity" | ||
| > | ||
| Sign Up | ||
| </Link> | ||
| </> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| "use client"; | ||
|
|
||
| import Link from "next/link"; | ||
| import { usePrivy } from "@privy-io/react-auth"; | ||
| import { siteConfig } from "@/lib/config"; | ||
|
|
||
| /** | ||
| * The mobile menu's Sign In entry. Hidden for signed-in sessions — on mobile | ||
| * the account menu in the header bar already carries "Open app" and log out. | ||
| */ | ||
| export function MobileSignInLink({ onNavigate }: { onNavigate: () => void }) { | ||
| const { ready, authenticated } = usePrivy(); | ||
| if (ready && authenticated) return null; | ||
| return ( | ||
| <Link | ||
| href={siteConfig.appUrl} | ||
| className="block px-3 py-2.5 text-sm font-ui font-medium text-(--foreground)/70 sm:hidden" | ||
| onClick={onNavigate} | ||
| > | ||
| Sign In | ||
| </Link> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
| import { accountInitial } from "@/lib/format/accountInitial"; | ||
|
|
||
| describe("accountInitial", () => { | ||
| it("returns the uppercased first letter of the email", () => { | ||
| expect(accountInitial("sweets@recoupable.dev")).toBe("S"); | ||
| }); | ||
|
|
||
| it("keeps an already-uppercase first letter", () => { | ||
| expect(accountInitial("Ana@example.com")).toBe("A"); | ||
| }); | ||
|
|
||
| it("skips non-alphanumeric leading characters", () => { | ||
| expect(accountInitial(".dots.first@example.com")).toBe("D"); | ||
| }); | ||
|
|
||
| it("uses a digit when the email starts with one", () => { | ||
| expect(accountInitial("9lives@example.com")).toBe("9"); | ||
| }); | ||
|
|
||
| it("falls back to ? when there is no email", () => { | ||
| expect(accountInitial(undefined)).toBe("?"); | ||
| expect(accountInitial(null)).toBe("?"); | ||
| expect(accountInitial("")).toBe("?"); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| /** | ||
| * The single character shown in the header avatar for a signed-in account: | ||
| * the first alphanumeric character of the email, uppercased. "?" when no | ||
| * email is available so the avatar never renders empty. | ||
| */ | ||
| export function accountInitial(email: string | null | undefined): string { | ||
| const match = email?.match(/[a-z0-9]/i); | ||
| return match ? match[0].toUpperCase() : "?"; | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: Screen-reader users can be told this is an ARIA menu, but keyboard interaction stays like plain links/buttons because menu keyboard behavior isn’t implemented. Consider either implementing full WAI-ARIA menu keyboard/focus handling or removing
role="menu"/role="menuitem"so semantics match actual behavior.Prompt for AI agents