11"use client" ;
22
3- import { useState } from "react" ;
3+ import { useState , useEffect } from "react" ;
4+ import { useAuth } from "@/lib/auth-context" ;
45import WaitlistModal from "@/components/WaitlistModal" ;
56
67export default function SiteHeader ( ) {
8+ const { signedIn, profile, signOut, loading } = useAuth ( ) ;
79 const [ modalOpen , setModalOpen ] = useState ( false ) ;
810 const [ mobileNavOpen , setMobileNavOpen ] = useState ( false ) ;
11+ const [ userDropdownOpen , setUserDropdownOpen ] = useState ( false ) ;
912 const openModal = ( ) => setModalOpen ( true ) ;
1013
14+ // Close dropdown on outside click
15+ useEffect ( ( ) => {
16+ if ( ! userDropdownOpen ) return ;
17+ const handler = ( ) => setUserDropdownOpen ( false ) ;
18+ document . addEventListener ( "click" , handler ) ;
19+ return ( ) => document . removeEventListener ( "click" , handler ) ;
20+ } , [ userDropdownOpen ] ) ;
21+
22+ const handleSignOut = async ( ) => {
23+ await signOut ( ) ;
24+ window . location . href = "/" ;
25+ } ;
26+
1127 return (
1228 < >
1329 < WaitlistModal open = { modalOpen } onClose = { ( ) => setModalOpen ( false ) } />
@@ -38,12 +54,73 @@ export default function SiteHeader() {
3854 </ a >
3955 </ div >
4056 < div className = "flex items-center gap-2 sm:gap-3" >
41- < a
42- href = "/auth/signup"
43- className = "rounded-lg bg-tc-green px-3 py-2 text-sm font-bold text-black transition-all hover:bg-tc-green-dim sm:px-4"
44- >
45- Sign Up
46- </ a >
57+ { ! loading && (
58+ signedIn ? (
59+ < div className = "flex items-center gap-2 relative" >
60+ < button
61+ type = "button"
62+ onClick = { ( e ) => {
63+ e . stopPropagation ( ) ;
64+ setUserDropdownOpen ( ( v ) => ! v ) ;
65+ } }
66+ className = "rounded-lg bg-tc-green/10 border border-tc-green/30 px-3 py-2 text-sm font-bold text-tc-green transition-all hover:bg-tc-green/20 flex items-center gap-2"
67+ >
68+ < span > { profile ?. display_name || profile ?. email || "Account" } </ span >
69+ < span className = "text-xs" > { userDropdownOpen ? "▲" : "▼" } </ span >
70+ </ button >
71+ { userDropdownOpen && (
72+ < div
73+ className = "absolute right-0 top-full mt-2 w-56 bg-tc-card border border-tc-border rounded-xl shadow-xl overflow-hidden z-50"
74+ onClick = { ( e ) => e . stopPropagation ( ) }
75+ >
76+ < div className = "px-4 py-3 border-b border-tc-border" >
77+ < p className = "text-sm text-white font-medium truncate" > { profile ?. display_name || "User" } </ p >
78+ < p className = "text-xs text-tc-text-dim truncate" > { profile ?. email } </ p >
79+ </ div >
80+ < div className = "py-1" >
81+ < a
82+ href = "/account"
83+ className = "block px-4 py-2 text-sm text-tc-text-dim hover:text-white hover:bg-tc-darker transition-colors"
84+ onClick = { ( ) => setUserDropdownOpen ( false ) }
85+ >
86+ Account Settings
87+ </ a >
88+ < a
89+ href = "/usage"
90+ className = "block px-4 py-2 text-sm text-tc-text-dim hover:text-white hover:bg-tc-darker transition-colors"
91+ onClick = { ( ) => setUserDropdownOpen ( false ) }
92+ >
93+ Usage & Billing
94+ </ a >
95+ </ div >
96+ < div className = "border-t border-tc-border" >
97+ < button
98+ onClick = { handleSignOut }
99+ className = "w-full text-left px-4 py-2 text-sm text-red-400 hover:bg-red-500/10 transition-colors"
100+ >
101+ Sign Out
102+ </ button >
103+ </ div >
104+ </ div >
105+ ) }
106+ </ div >
107+ ) : (
108+ < >
109+ < a
110+ href = "/auth/login"
111+ className = "hidden lg:inline text-sm text-tc-text-dim hover:text-tc-green transition-colors"
112+ >
113+ Log In
114+ </ a >
115+ < a
116+ href = "/auth/signup"
117+ className = "rounded-lg bg-tc-green px-3 py-2 text-sm font-bold text-black transition-all hover:bg-tc-green-dim sm:px-4"
118+ >
119+ Sign Up
120+ </ a >
121+ </ >
122+ )
123+ ) }
47124 < button
48125 type = "button"
49126 onClick = { ( ) => setMobileNavOpen ( ( open ) => ! open ) }
@@ -54,18 +131,14 @@ export default function SiteHeader() {
54131 < span className = "text-lg" > { mobileNavOpen ? "✕" : "☰" } </ span >
55132 </ button >
56133 < div className = "hidden lg:flex items-center gap-3" >
57- < a
58- href = "/auth/login"
59- className = "text-sm text-tc-text-dim hover:text-tc-green transition-colors"
60- >
61- Log In
62- </ a >
63- < button
64- onClick = { openModal }
65- className = "rounded-lg border border-tc-green/30 px-4 py-2 text-sm font-bold text-tc-green transition-all hover:bg-tc-green/10"
66- >
67- Join Waitlist
68- </ button >
134+ { ! signedIn && ! loading && (
135+ < button
136+ onClick = { openModal }
137+ className = "rounded-lg border border-tc-green/30 px-4 py-2 text-sm font-bold text-tc-green transition-all hover:bg-tc-green/10"
138+ >
139+ Join Waitlist
140+ </ button >
141+ ) }
69142 </ div >
70143 </ div >
71144 </ div >
@@ -79,16 +152,34 @@ export default function SiteHeader() {
79152 < a href = "/#pricing" className = "hover:text-tc-green transition-colors" onClick = { ( ) => setMobileNavOpen ( false ) } > Pricing</ a >
80153 < a href = "/investors" className = "hover:text-tc-green transition-colors" onClick = { ( ) => setMobileNavOpen ( false ) } > Investors</ a >
81154 < a href = "/#faq" className = "hover:text-tc-green transition-colors" onClick = { ( ) => setMobileNavOpen ( false ) } > FAQ</ a >
82- < a href = "/auth/login" className = "hover:text-tc-green transition-colors" onClick = { ( ) => setMobileNavOpen ( false ) } > Log In</ a >
83- < button
84- onClick = { ( ) => {
85- setMobileNavOpen ( false ) ;
86- openModal ( ) ;
87- } }
88- className = "rounded-lg border border-tc-green/30 px-4 py-2 text-left font-bold text-tc-green transition-all hover:bg-tc-green/10"
89- >
90- Join Waitlist
91- </ button >
155+ { signedIn ? (
156+ < >
157+ < a href = "/account" className = "text-tc-green transition-colors" onClick = { ( ) => setMobileNavOpen ( false ) } > Account</ a >
158+ < button
159+ onClick = { async ( ) => {
160+ setMobileNavOpen ( false ) ;
161+ await signOut ( ) ;
162+ window . location . href = "/" ;
163+ } }
164+ className = "text-left text-red-400 hover:text-red-300 transition-colors"
165+ >
166+ Sign Out
167+ </ button >
168+ </ >
169+ ) : (
170+ < >
171+ < a href = "/auth/login" className = "hover:text-tc-green transition-colors" onClick = { ( ) => setMobileNavOpen ( false ) } > Log In</ a >
172+ < button
173+ onClick = { ( ) => {
174+ setMobileNavOpen ( false ) ;
175+ openModal ( ) ;
176+ } }
177+ className = "rounded-lg border border-tc-green/30 px-4 py-2 text-left font-bold text-tc-green transition-all hover:bg-tc-green/10"
178+ >
179+ Join Waitlist
180+ </ button >
181+ </ >
182+ ) }
92183 < a
93184 href = "https://github.com/profullstack/threatcrush"
94185 target = "_blank"
0 commit comments